Version: 2024-10
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation discountCodeAppCreate($codeAppDiscount: DiscountCodeAppInput!) { discountCodeAppCreate(codeAppDiscount: $codeAppDiscount) { codeAppDiscount { discountId title appDiscountType { description functionId } combinesWith { orderDiscounts productDiscounts shippingDiscounts } codes(first: 100) { nodes { code } } status usageLimit } userErrors { field message } } }\",\n \"variables\": {\n \"codeAppDiscount\": {\n \"code\": \"APP_DISCOUNT\",\n \"title\": \"Take 5$ from order discount\",\n \"functionId\": \"b42a026e-f96f-4423-938b-54ade7a21161\",\n \"appliesOncePerCustomer\": true,\n \"combinesWith\": {\n \"orderDiscounts\": true,\n \"productDiscounts\": true,\n \"shippingDiscounts\": true\n },\n \"startsAt\": \"2021-02-02T17:09:21Z\",\n \"endsAt\": \"2022-02-02T17:09:21Z\",\n \"usageLimit\": 1,\n \"metafields\": [\n {\n \"namespace\": \"default\",\n \"key\": \"function-configuration\",\n \"type\": \"json\",\n \"value\": \"{\\\"discounts\\\":[{\\\"value\\\":{\\\"fixedAmount\\\":{\\\"amount\\\":5}},\\\"targets\\\":\\n [{\\\"orderSubtotal\\\":{\\\"excludedVariantIds\\\":[]}}]}],\\\"discountApplicationStrategy\\\":\\\"FIRST\\\"}\"\n }\n ]\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation discountCodeAppCreate($codeAppDiscount: DiscountCodeAppInput!) {\n discountCodeAppCreate(codeAppDiscount: $codeAppDiscount) {\n codeAppDiscount {\n discountId\n title\n appDiscountType {\n description\n functionId\n }\n combinesWith {\n orderDiscounts\n productDiscounts\n shippingDiscounts\n }\n codes(first: 100) {\n nodes {\n code\n }\n }\n status\n usageLimit\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"codeAppDiscount\": {\n \"code\": \"APP_DISCOUNT\",\n \"title\": \"Take 5$ from order discount\",\n \"functionId\": \"b42a026e-f96f-4423-938b-54ade7a21161\",\n \"appliesOncePerCustomer\": true,\n \"combinesWith\": {\n \"orderDiscounts\": true,\n \"productDiscounts\": true,\n \"shippingDiscounts\": true\n },\n \"startsAt\": \"2021-02-02T17:09:21Z\",\n \"endsAt\": \"2022-02-02T17:09:21Z\",\n \"usageLimit\": 1,\n \"metafields\": [\n {\n \"namespace\": \"default\",\n \"key\": \"function-configuration\",\n \"type\": \"json\",\n \"value\": \"{\\\"discounts\\\":[{\\\"value\\\":{\\\"fixedAmount\\\":{\\\"amount\\\":5}},\\\"targets\\\":\\n [{\\\"orderSubtotal\\\":{\\\"excludedVariantIds\\\":[]}}]}],\\\"discountApplicationStrategy\\\":\\\"FIRST\\\"}\"\n }\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 discountCodeAppCreate($codeAppDiscount: DiscountCodeAppInput!) {\n discountCodeAppCreate(codeAppDiscount: $codeAppDiscount) {\n codeAppDiscount {\n discountId\n title\n appDiscountType {\n description\n functionId\n }\n combinesWith {\n orderDiscounts\n productDiscounts\n shippingDiscounts\n }\n codes(first: 100) {\n nodes {\n code\n }\n }\n status\n usageLimit\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"codeAppDiscount\": {\n \"code\": \"APP_DISCOUNT\",\n \"title\": \"Take 5$ from order discount\",\n \"functionId\": \"b42a026e-f96f-4423-938b-54ade7a21161\",\n \"appliesOncePerCustomer\": true,\n \"combinesWith\": {\n \"orderDiscounts\": true,\n \"productDiscounts\": true,\n \"shippingDiscounts\": true\n },\n \"startsAt\": \"2021-02-02T17:09:21Z\",\n \"endsAt\": \"2022-02-02T17:09:21Z\",\n \"usageLimit\": 1,\n \"metafields\": [{\"namespace\"=>\"default\", \"key\"=>\"function-configuration\", \"type\"=>\"json\", \"value\"=>\"{\\\"discounts\\\":[{\\\"value\\\":{\\\"fixedAmount\\\":{\\\"amount\\\":5}},\\\"targets\\\":\\n [{\\\"orderSubtotal\\\":{\\\"excludedVariantIds\\\":[]}}]}],\\\"discountApplicationStrategy\\\":\\\"FIRST\\\"}\"}]\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 = <<[\n \"code\" => \"APP_DISCOUNT\",\n \"title\" => \"Take 5$ from order discount\",\n \"functionId\" => \"b42a026e-f96f-4423-938b-54ade7a21161\",\n \"appliesOncePerCustomer\" => true,\n \"combinesWith\" => [\n \"orderDiscounts\" => true,\n \"productDiscounts\" => true,\n \"shippingDiscounts\" => true,\n ],\n \"startsAt\" => \"2021-02-02T17:09:21Z\",\n \"endsAt\" => \"2022-02-02T17:09:21Z\",\n \"usageLimit\" => 1,\n \"metafields\" => [{\"namespace\"=>\"default\", \"key\"=>\"function-configuration\", \"type\"=>\"json\", \"value\"=>\"{\\\"discounts\\\":[{\\\"value\\\":{\\\"fixedAmount\\\":{\\\"amount\\\":5}},\\\"targets\\\":\\n [{\\\"orderSubtotal\\\":{\\\"excludedVariantIds\\\":[]}}]}],\\\"discountApplicationStrategy\\\":\\\"FIRST\\\"}\"}],\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 discountCodeAppCreate($codeAppDiscount: DiscountCodeAppInput!) {\n discountCodeAppCreate(codeAppDiscount: $codeAppDiscount) {\n codeAppDiscount {\n discountId\n title\n appDiscountType {\n description\n functionId\n }\n combinesWith {\n orderDiscounts\n productDiscounts\n shippingDiscounts\n }\n codes(first: 100) {\n nodes {\n code\n }\n }\n status\n usageLimit\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"codeAppDiscount\": {\n \"code\": \"APP_DISCOUNT\",\n \"title\": \"Take 5$ from order discount\",\n \"functionId\": \"b42a026e-f96f-4423-938b-54ade7a21161\",\n \"appliesOncePerCustomer\": true,\n \"combinesWith\": {\n \"orderDiscounts\": true,\n \"productDiscounts\": true,\n \"shippingDiscounts\": true\n },\n \"startsAt\": \"2021-02-02T17:09:21Z\",\n \"endsAt\": \"2022-02-02T17:09:21Z\",\n \"usageLimit\": 1,\n \"metafields\": [\n {\n \"namespace\": \"default\",\n \"key\": \"function-configuration\",\n \"type\": \"json\",\n \"value\": \"{\\\"discounts\\\":[{\\\"value\\\":{\\\"fixedAmount\\\":{\\\"amount\\\":5}},\\\"targets\\\":\\n [{\\\"orderSubtotal\\\":{\\\"excludedVariantIds\\\":[]}}]}],\\\"discountApplicationStrategy\\\":\\\"FIRST\\\"}\"\n }\n ]\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation discountCodeAppCreate($codeAppDiscount: DiscountCodeAppInput!) {\n discountCodeAppCreate(codeAppDiscount: $codeAppDiscount) {\n codeAppDiscount {\n discountId\n title\n appDiscountType {\n description\n functionId\n }\n combinesWith {\n orderDiscounts\n productDiscounts\n shippingDiscounts\n }\n codes(first: 100) {\n nodes {\n code\n }\n }\n status\n usageLimit\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "codeAppDiscount": { "code": "APP_DISCOUNT", "title": "Take 5$ from order discount", "functionId": "b42a026e-f96f-4423-938b-54ade7a21161", "appliesOncePerCustomer": true, "combinesWith": { "orderDiscounts": true, "productDiscounts": true, "shippingDiscounts": true }, "startsAt": "2021-02-02T17:09:21Z", "endsAt": "2022-02-02T17:09:21Z", "usageLimit": 1, "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\"discounts\":[{\"value\":{\"fixedAmount\":{\"amount\":5}},\"targets\":\n [{\"orderSubtotal\":{\"excludedVariantIds\":[]}}]}],\"discountApplicationStrategy\":\"FIRST\"}" } ] } }
response: { "data": { "discountCodeAppCreate": { "codeAppDiscount": { "discountId": "gid://shopify/DiscountCodeNode/1057371204", "title": "Take 5$ from order discount", "appDiscountType": { "description": "my function does a thing", "functionId": "9dfed7ac-5b56-4696-920a-796985c30509" }, "combinesWith": { "orderDiscounts": true, "productDiscounts": true, "shippingDiscounts": true }, "codes": { "nodes": [ { "code": "APP_DISCOUNT" } ] }, "status": "EXPIRED", "usageLimit": 1 }, "userErrors": [] } } }