Anchor to priceRuleCreateprice
priceRuleCreate
mutationDeprecated
Requires access scope.
Create a price rule using the input. Use instead.
Anchor to Arguments
Arguments
- Anchor to priceRuleprice•
Rule PriceRule requiredInput! The input fields to create a price rule.
- Anchor to priceRuleDiscountCodeprice•
Rule Discount Code The input fields to create a discount code for the price rule.
Was this section helpful?
Anchor to PriceRuleCreatePayload returnsPriceRuleCreatePayload returns
- Anchor to priceRuleprice•
Rule The newly created price rule.
- Anchor to priceRuleDiscountCodeprice•
Rule Discount Code The newly created discount code.
- Anchor to priceRuleUserErrorsprice•
Rule User Errors [PriceRule non-nullUser Error!]! The list of errors that occurred from executing the mutation.
- Anchor to userErrorsuser•
Errors The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create a price rule
- priceRuleCreate reference
Examples
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 {
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-04/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();
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"
}
}
},
},
});
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)
Input variables
JSON{
"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
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