price Rule Createmutation deprecated
mutation
2024-01
Requires write
access scope.
Create a price rule using the input. Use discount
instead.
Arguments
The input fields to create a price rule.
Anchor to priceRuleDiscountCodepriceRuleDiscountCodeThe input fields to create a discount code for the price rule.
Was this section helpful?
PriceRuleCreatePayload returns
The newly created price rule.
Anchor to PriceRuleCreatePayload.priceRuleDiscountCodepriceRule Discount Code The newly created discount code.
The list of errors that occurred from executing the mutation.
The list of errors that occurred from executing the mutation. Use
price
instead.Rule User Errors
Was this section helpful?
Examples
Hide code
DescriptionCopy
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 } } }
curl -X POST \ https://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "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 } } }", "variables": { "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" } } } }'
const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql 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 } } }`, { variables: { "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" } } }, }, ); 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 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 } } } QUERY variables = { "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 = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "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 } } }`, "variables": { "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" } } }, }, });
use Shopify\Clients\Graphql; $client = new Graphql("your-development-store.myshopify.com", $accessToken); $query = <<<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 } } } QUERY; $variables = [ "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 = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{ "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" } } }
Hide code
Response
JSON
{ "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": [] } }