Version: 2024-01
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation priceRuleCreate($priceRule: PriceRuleInput!, $priceRuleDiscountCode: PriceRuleDiscountCodeInput) { priceRuleCreate(priceRule: $priceRule, priceRuleDiscountCode: $priceRuleDiscountCode) { priceRule { id title validityPeriod { start } allocationMethod itemEntitlements { products(first: 3) { edges { node { id } } } targetAllLineItems } valueV2 { ... on MoneyV2 { amount currencyCode } } customerSelection { forAllCustomers } oncePerCustomer usageLimit target } priceRuleDiscountCode { id code } priceRuleUserErrors { code field message } } }\",\n \"variables\": {\n \"priceRule\": {\n \"title\": \"Boots Discount\",\n \"allocationMethod\": \"ACROSS\",\n \"customerSelection\": {\n \"forAllCustomers\": true\n },\n \"itemEntitlements\": {\n \"targetAllLineItems\": false,\n \"productIds\": [\n \"gid://shopify/Product/121709582\"\n ]\n },\n \"target\": \"LINE_ITEM\",\n \"validityPeriod\": {\n \"start\": \"2016-08-29T12:00:00-04:00\"\n },\n \"value\": {\n \"fixedAmountValue\": \"-10.0\"\n }\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation priceRuleCreate($priceRule: PriceRuleInput!, $priceRuleDiscountCode: PriceRuleDiscountCodeInput) {\n priceRuleCreate(priceRule: $priceRule, priceRuleDiscountCode: $priceRuleDiscountCode) {\n priceRule {\n id\n title\n validityPeriod {\n start\n }\n allocationMethod\n itemEntitlements {\n products(first: 3) {\n edges {\n node {\n id\n }\n }\n }\n targetAllLineItems\n }\n valueV2 {\n ... on MoneyV2 {\n amount\n currencyCode\n }\n }\n customerSelection {\n forAllCustomers\n }\n oncePerCustomer\n usageLimit\n target\n }\n priceRuleDiscountCode {\n id\n code\n }\n priceRuleUserErrors {\n code\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"priceRule\": {\n \"title\": \"Boots Discount\",\n \"allocationMethod\": \"ACROSS\",\n \"customerSelection\": {\n \"forAllCustomers\": true\n },\n \"itemEntitlements\": {\n \"targetAllLineItems\": false,\n \"productIds\": [\n \"gid://shopify/Product/121709582\"\n ]\n },\n \"target\": \"LINE_ITEM\",\n \"validityPeriod\": {\n \"start\": \"2016-08-29T12:00:00-04:00\"\n },\n \"value\": {\n \"fixedAmountValue\": \"-10.0\"\n }\n }\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation priceRuleCreate($priceRule: PriceRuleInput!, $priceRuleDiscountCode: PriceRuleDiscountCodeInput) {\n priceRuleCreate(priceRule: $priceRule, priceRuleDiscountCode: $priceRuleDiscountCode) {\n priceRule {\n id\n title\n validityPeriod {\n start\n }\n allocationMethod\n itemEntitlements {\n products(first: 3) {\n edges {\n node {\n id\n }\n }\n }\n targetAllLineItems\n }\n valueV2 {\n ... on MoneyV2 {\n amount\n currencyCode\n }\n }\n customerSelection {\n forAllCustomers\n }\n oncePerCustomer\n usageLimit\n target\n }\n priceRuleDiscountCode {\n id\n code\n }\n priceRuleUserErrors {\n code\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"priceRule\": {\n \"title\": \"Boots Discount\",\n \"allocationMethod\": \"ACROSS\",\n \"customerSelection\": {\n \"forAllCustomers\": true\n },\n \"itemEntitlements\": {\n \"targetAllLineItems\": false,\n \"productIds\": [\"gid://shopify/Product/121709582\"]\n },\n \"target\": \"LINE_ITEM\",\n \"validityPeriod\": {\n \"start\": \"2016-08-29T12:00:00-04:00\"\n },\n \"value\": {\n \"fixedAmountValue\": \"-10.0\"\n }\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation priceRuleCreate($priceRule: PriceRuleInput!, $priceRuleDiscountCode: PriceRuleDiscountCodeInput) {\n priceRuleCreate(priceRule: $priceRule, priceRuleDiscountCode: $priceRuleDiscountCode) {\n priceRule {\n id\n title\n validityPeriod {\n start\n }\n allocationMethod\n itemEntitlements {\n products(first: 3) {\n edges {\n node {\n id\n }\n }\n }\n targetAllLineItems\n }\n valueV2 {\n ... on MoneyV2 {\n amount\n currencyCode\n }\n }\n customerSelection {\n forAllCustomers\n }\n oncePerCustomer\n usageLimit\n target\n }\n priceRuleDiscountCode {\n id\n code\n }\n priceRuleUserErrors {\n code\n field\n message\n }\n }\n }\nQUERY;\n\n$variables = [\n \"priceRule\" => [\n \"title\" => \"Boots Discount\",\n \"allocationMethod\" => \"ACROSS\",\n \"customerSelection\" => [\n \"forAllCustomers\" => true,\n ],\n \"itemEntitlements\" => [\n \"targetAllLineItems\" => false,\n \"productIds\" => [\"gid://shopify/Product/121709582\"],\n ],\n \"target\" => \"LINE_ITEM\",\n \"validityPeriod\" => [\n \"start\" => \"2016-08-29T12:00:00-04:00\",\n ],\n \"value\" => [\n \"fixedAmountValue\" => \"-10.0\",\n ],\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation priceRuleCreate($priceRule: PriceRuleInput!, $priceRuleDiscountCode: PriceRuleDiscountCodeInput) {\n priceRuleCreate(priceRule: $priceRule, priceRuleDiscountCode: $priceRuleDiscountCode) {\n priceRule {\n id\n title\n validityPeriod {\n start\n }\n allocationMethod\n itemEntitlements {\n products(first: 3) {\n edges {\n node {\n id\n }\n }\n }\n targetAllLineItems\n }\n valueV2 {\n ... on MoneyV2 {\n amount\n currencyCode\n }\n }\n customerSelection {\n forAllCustomers\n }\n oncePerCustomer\n usageLimit\n target\n }\n priceRuleDiscountCode {\n id\n code\n }\n priceRuleUserErrors {\n code\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"priceRule\": {\n \"title\": \"Boots Discount\",\n \"allocationMethod\": \"ACROSS\",\n \"customerSelection\": {\n \"forAllCustomers\": true\n },\n \"itemEntitlements\": {\n \"targetAllLineItems\": false,\n \"productIds\": [\n \"gid://shopify/Product/121709582\"\n ]\n },\n \"target\": \"LINE_ITEM\",\n \"validityPeriod\": {\n \"start\": \"2016-08-29T12:00:00-04:00\"\n },\n \"value\": {\n \"fixedAmountValue\": \"-10.0\"\n }\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation priceRuleCreate($priceRule: PriceRuleInput!, $priceRuleDiscountCode: PriceRuleDiscountCodeInput) {\n priceRuleCreate(priceRule: $priceRule, priceRuleDiscountCode: $priceRuleDiscountCode) {\n priceRule {\n id\n title\n validityPeriod {\n start\n }\n allocationMethod\n itemEntitlements {\n products(first: 3) {\n edges {\n node {\n id\n }\n }\n }\n targetAllLineItems\n }\n valueV2 {\n ... on MoneyV2 {\n amount\n currencyCode\n }\n }\n customerSelection {\n forAllCustomers\n }\n oncePerCustomer\n usageLimit\n target\n }\n priceRuleDiscountCode {\n id\n code\n }\n priceRuleUserErrors {\n code\n field\n message\n }\n }\n}"
input: { "priceRule": { "title": "Boots Discount", "allocationMethod": "ACROSS", "customerSelection": { "forAllCustomers": true }, "itemEntitlements": { "targetAllLineItems": false, "productIds": [ "gid://shopify/Product/121709582" ] }, "target": "LINE_ITEM", "validityPeriod": { "start": "2016-08-29T12:00:00-04:00" }, "value": { "fixedAmountValue": "-10.0" } } }
response: { "data": { "priceRuleCreate": { "priceRule": { "id": "gid://shopify/PriceRule/1057371212", "title": "Boots Discount", "validityPeriod": { "start": "2016-08-29T16:00:00Z" }, "allocationMethod": "ACROSS", "itemEntitlements": { "products": { "edges": [ { "node": { "id": "gid://shopify/Product/121709582" } } ] }, "targetAllLineItems": false }, "valueV2": { "amount": "-10.0", "currencyCode": "USD" }, "customerSelection": { "forAllCustomers": true }, "oncePerCustomer": false, "usageLimit": null, "target": "LINE_ITEM" }, "priceRuleDiscountCode": null, "priceRuleUserErrors": [] } } }