discount Automatic App Createmutation
mutation
2024-10latest
Requires
write_discounts
access scope.
Creates an app discount.
Arguments
The input data used to create the app discount.
Was this section helpful?
DiscountAutomaticAppCreatePayload returns
The created app discount.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Examples
Hide code
DescriptionCopy
mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) { discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) { userErrors { field message } automaticAppDiscount { discountId title startsAt endsAt status appDiscountType { appKey functionId } combinesWith { orderDiscounts productDiscounts shippingDiscounts } } } }
curl -X POST \ https://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) { discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) { userErrors { field message } automaticAppDiscount { discountId title startsAt endsAt status appDiscountType { appKey functionId } combinesWith { orderDiscounts productDiscounts shippingDiscounts } } } }", "variables": { "automaticAppDiscount": { "title": "Take 5$ from discount", "functionId": "a28a1b8c-584c-40cd-a822-f53c8d01bb5f", "combinesWith": { "orderDiscounts": true, "productDiscounts": true, "shippingDiscounts": true }, "startsAt": "2021-02-02T17:09:21Z", "endsAt": "2022-02-02T17:09:21Z", "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\"discounts\":[{\"value\":{\"fixedAmount\":{\"amount\":5}},\"targets\":\n [{\"orderSubtotal\":{\"excludedVariantIds\":[]}}]}],\"discountApplicationStrategy\":\"FIRST\"}" } ] } } }'
const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) { discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) { userErrors { field message } automaticAppDiscount { discountId title startsAt endsAt status appDiscountType { appKey functionId } combinesWith { orderDiscounts productDiscounts shippingDiscounts } } } }`, { variables: { "automaticAppDiscount": { "title": "Take 5$ from discount", "functionId": "a28a1b8c-584c-40cd-a822-f53c8d01bb5f", "combinesWith": { "orderDiscounts": true, "productDiscounts": true, "shippingDiscounts": true }, "startsAt": "2021-02-02T17:09:21Z", "endsAt": "2022-02-02T17:09:21Z", "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\"discounts\":[{\"value\":{\"fixedAmount\":{\"amount\":5}},\"targets\":\n [{\"orderSubtotal\":{\"excludedVariantIds\":[]}}]}],\"discountApplicationStrategy\":\"FIRST\"}" } ] } }, }, ); const data = await response.json();
session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) { discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) { userErrors { field message } automaticAppDiscount { discountId title startsAt endsAt status appDiscountType { appKey functionId } combinesWith { orderDiscounts productDiscounts shippingDiscounts } } } } QUERY variables = { "automaticAppDiscount": { "title": "Take 5$ from discount", "functionId": "a28a1b8c-584c-40cd-a822-f53c8d01bb5f", "combinesWith": { "orderDiscounts": true, "productDiscounts": true, "shippingDiscounts": true }, "startsAt": "2021-02-02T17:09:21Z", "endsAt": "2022-02-02T17:09:21Z", "metafields": [{"namespace"=>"default", "key"=>"function-configuration", "type"=>"json", "value"=>"{\"discounts\":[{\"value\":{\"fixedAmount\":{\"amount\":5}},\"targets\":\n [{\"orderSubtotal\":{\"excludedVariantIds\":[]}}]}],\"discountApplicationStrategy\":\"FIRST\"}"}] } } response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) { discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) { userErrors { field message } automaticAppDiscount { discountId title startsAt endsAt status appDiscountType { appKey functionId } combinesWith { orderDiscounts productDiscounts shippingDiscounts } } } }`, "variables": { "automaticAppDiscount": { "title": "Take 5$ from discount", "functionId": "a28a1b8c-584c-40cd-a822-f53c8d01bb5f", "combinesWith": { "orderDiscounts": true, "productDiscounts": true, "shippingDiscounts": true }, "startsAt": "2021-02-02T17:09:21Z", "endsAt": "2022-02-02T17:09:21Z", "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\"discounts\":[{\"value\":{\"fixedAmount\":{\"amount\":5}},\"targets\":\n [{\"orderSubtotal\":{\"excludedVariantIds\":[]}}]}],\"discountApplicationStrategy\":\"FIRST\"}" } ] } }, }, });
use Shopify\Clients\Graphql; $client = new Graphql("your-development-store.myshopify.com", $accessToken); $query = <<<QUERY mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) { discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) { userErrors { field message } automaticAppDiscount { discountId title startsAt endsAt status appDiscountType { appKey functionId } combinesWith { orderDiscounts productDiscounts shippingDiscounts } } } } QUERY; $variables = [ "automaticAppDiscount" => [ "title" => "Take 5$ from discount", "functionId" => "a28a1b8c-584c-40cd-a822-f53c8d01bb5f", "combinesWith" => [ "orderDiscounts" => true, "productDiscounts" => true, "shippingDiscounts" => true, ], "startsAt" => "2021-02-02T17:09:21Z", "endsAt" => "2022-02-02T17:09:21Z", "metafields" => [{"namespace"=>"default", "key"=>"function-configuration", "type"=>"json", "value"=>"{\"discounts\":[{\"value\":{\"fixedAmount\":{\"amount\":5}},\"targets\":\n [{\"orderSubtotal\":{\"excludedVariantIds\":[]}}]}],\"discountApplicationStrategy\":\"FIRST\"}"}], ], ]; $response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{ "automaticAppDiscount": { "title": "Take 5$ from discount", "functionId": "a28a1b8c-584c-40cd-a822-f53c8d01bb5f", "combinesWith": { "orderDiscounts": true, "productDiscounts": true, "shippingDiscounts": true }, "startsAt": "2021-02-02T17:09:21Z", "endsAt": "2022-02-02T17:09:21Z", "metafields": [ { "namespace": "default", "key": "function-configuration", "type": "json", "value": "{\"discounts\":[{\"value\":{\"fixedAmount\":{\"amount\":5}},\"targets\":\n [{\"orderSubtotal\":{\"excludedVariantIds\":[]}}]}],\"discountApplicationStrategy\":\"FIRST\"}" } ] } }
Hide code
Response
JSON
{ "discountAutomaticAppCreate": { "userErrors": [ { "field": [ "automaticAppDiscount" ], "message": "is not supported with these combines_with settings" } ], "automaticAppDiscount": null } }