Version: 2024-01
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/api/2024-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Storefront-Access-Token: {storefront_access_token}' \\\n-d '{\n\"query\": \"mutation applyDiscountCodeToCheckout($checkoutId: ID!, $discountCode: String!) { checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) { checkout { discountApplications(first: 10) { edges { node { allocationMethod targetSelection targetType } } } } checkoutUserErrors { message code field } } }\",\n \"variables\": {\n \"checkoutId\": \"gid://shopify/Checkout/9234567890qwerty\",\n \"discountCode\": \"fixed_amount_off_code\"\n }\n}'\n" Node example: "const client = new shopify.clients.Storefront({\n domain: 'your-development-store.myshopify.com',\n storefrontAccessToken,\n});\nconst data = await client.query({\n data: {\n \"query\": `mutation applyDiscountCodeToCheckout($checkoutId: ID!, $discountCode: String!) {\n checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) {\n checkout {\n discountApplications(first: 10) {\n edges {\n node {\n allocationMethod\n targetSelection\n targetType\n }\n }\n }\n }\n checkoutUserErrors {\n message\n code\n field\n }\n }\n }`,\n \"variables\": {\n \"checkoutId\": \"gid://shopify/Checkout/9234567890qwerty\",\n \"discountCode\": \"fixed_amount_off_code\"\n },\n },\n});\n" Ruby example: null PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new ShopifyClientsStorefront(\"your-development-store.myshopify.com\", $storefrontAccessToken);\n$query = <<<QUERY\n mutation applyDiscountCodeToCheckout($checkoutId: ID!, $discountCode: String!) {\n checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) {\n checkout {\n discountApplications(first: 10) {\n edges {\n node {\n allocationMethod\n targetSelection\n targetType\n }\n }\n }\n }\n checkoutUserErrors {\n message\n code\n field\n }\n }\n }\nQUERY;\n\n$variables = [\n \"checkoutId\" => \"gid://shopify/Checkout/9234567890qwerty\",\n \"discountCode\" => \"fixed_amount_off_code\",\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { storefront } = await unauthenticated.storefront(\n 'your-development-store.myshopify.com'\n);\n\nconst response = await storefront.graphql(\n `#graphql\n mutation applyDiscountCodeToCheckout($checkoutId: ID!, $discountCode: String!) {\n checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) {\n checkout {\n discountApplications(first: 10) {\n edges {\n node {\n allocationMethod\n targetSelection\n targetType\n }\n }\n }\n }\n checkoutUserErrors {\n message\n code\n field\n }\n }\n }`,\n {\n variables: {\n \"checkoutId\": \"gid://shopify/Checkout/9234567890qwerty\",\n \"discountCode\": \"fixed_amount_off_code\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation applyDiscountCodeToCheckout($checkoutId: ID!, $discountCode: String!) {\n checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) {\n checkout {\n discountApplications(first: 10) {\n edges {\n node {\n allocationMethod\n targetSelection\n targetType\n }\n }\n }\n }\n checkoutUserErrors {\n message\n code\n field\n }\n }\n}"
input: { "checkoutId": "gid://shopify/Checkout/9234567890qwerty", "discountCode": "fixed_amount_off_code" }
response: { "data": { "checkoutDiscountCodeApplyV2": { "checkout": { "discountApplications": { "edges": [ { "node": { "allocationMethod": "ACROSS", "targetSelection": "ALL", "targetType": "LINE_ITEM" } } ] } }, "checkoutUserErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/api/2024-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Storefront-Access-Token: {storefront_access_token}' \\\n-d '{\n\"query\": \"mutation applyDiscountCodeToCheckout($checkoutId: ID!, $discountCode: String!) { checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) { checkout { discountApplications(first: 10) { edges { node { allocationMethod targetSelection targetType } } } } checkoutUserErrors { message code field } } }\",\n \"variables\": {\n \"checkoutId\": \"gid://shopify/Checkout/9234567890qwerty\",\n \"discountCode\": \"fixed_amount_off_code\"\n }\n}'\n" Node example: "const client = new shopify.clients.Storefront({\n domain: 'your-development-store.myshopify.com',\n storefrontAccessToken,\n});\nconst data = await client.query({\n data: {\n \"query\": `mutation applyDiscountCodeToCheckout($checkoutId: ID!, $discountCode: String!) {\n checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) {\n checkout {\n discountApplications(first: 10) {\n edges {\n node {\n allocationMethod\n targetSelection\n targetType\n }\n }\n }\n }\n checkoutUserErrors {\n message\n code\n field\n }\n }\n }`,\n \"variables\": {\n \"checkoutId\": \"gid://shopify/Checkout/9234567890qwerty\",\n \"discountCode\": \"fixed_amount_off_code\"\n },\n },\n});\n" Ruby example: null PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new ShopifyClientsStorefront(\"your-development-store.myshopify.com\", $storefrontAccessToken);\n$query = <<<QUERY\n mutation applyDiscountCodeToCheckout($checkoutId: ID!, $discountCode: String!) {\n checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) {\n checkout {\n discountApplications(first: 10) {\n edges {\n node {\n allocationMethod\n targetSelection\n targetType\n }\n }\n }\n }\n checkoutUserErrors {\n message\n code\n field\n }\n }\n }\nQUERY;\n\n$variables = [\n \"checkoutId\" => \"gid://shopify/Checkout/9234567890qwerty\",\n \"discountCode\" => \"fixed_amount_off_code\",\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { storefront } = await unauthenticated.storefront(\n 'your-development-store.myshopify.com'\n);\n\nconst response = await storefront.graphql(\n `#graphql\n mutation applyDiscountCodeToCheckout($checkoutId: ID!, $discountCode: String!) {\n checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) {\n checkout {\n discountApplications(first: 10) {\n edges {\n node {\n allocationMethod\n targetSelection\n targetType\n }\n }\n }\n }\n checkoutUserErrors {\n message\n code\n field\n }\n }\n }`,\n {\n variables: {\n \"checkoutId\": \"gid://shopify/Checkout/9234567890qwerty\",\n \"discountCode\": \"fixed_amount_off_code\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation applyDiscountCodeToCheckout($checkoutId: ID!, $discountCode: String!) {\n checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) {\n checkout {\n discountApplications(first: 10) {\n edges {\n node {\n allocationMethod\n targetSelection\n targetType\n }\n }\n }\n }\n checkoutUserErrors {\n message\n code\n field\n }\n }\n}"
input: { "checkoutId": "gid://shopify/Checkout/9234567890qwerty", "discountCode": "fixed_amount_off_code" }
response: { "data": { "checkoutDiscountCodeApplyV2": null }, "errors": [ { "message": "Too many requests. Please try again in a few seconds", "locations": [ { "line": 2, "column": 3 } ], "path": [ "checkoutDiscountCodeApplyV2" ] } ] }