Anchor to priceRuleDiscountCodeUpdateprice
priceRuleDiscountCodeUpdate
mutationDeprecated
Requires access scope.
Update a discount code for a price rule. Use instead.
Anchor to Arguments
Arguments
- Anchor to codecode•String!required
The new code of a price rule.
- Anchor to priceRuleIdprice•
Rule Id ID!required The ID of the price rule object.
Was this section helpful?
Anchor to PriceRuleDiscountCodeUpdatePayload returnsPriceRuleDiscountCodeUpdatePayload returns
- Anchor to priceRuleprice•
Rule The updated price rule.
- Anchor to priceRuleDiscountCodeprice•
Rule Discount Code The updated 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?
- Update a discount code for a price rule
- priceRuleDiscountCodeUpdate reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation priceRuleDiscountCodeUpdate($priceRuleId: ID!, $code: String!) {6 priceRuleDiscountCodeUpdate(priceRuleId: $priceRuleId, code: $code) {7 priceRuleUserErrors {8 field9 message10 code11 }12 priceRule {13 id14 title15 allocationMethod16 target17 validityPeriod {18 start19 end20 }21 }22 priceRuleDiscountCode {23 code24 }25 }26 }`,27 {28 variables: {29 "priceRuleId": "gid://shopify/PriceRule/1057371214",30 "code": "NEWCODE"31 },32 },33);3435const data = await response.json();36
mutation priceRuleDiscountCodeUpdate($priceRuleId: ID!, $code: String!) {
priceRuleDiscountCodeUpdate(priceRuleId: $priceRuleId, code: $code) {
priceRuleUserErrors {
field
message
code
}
priceRule {
id
title
allocationMethod
target
validityPeriod {
start
end
}
}
priceRuleDiscountCode {
code
}
}
}
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 priceRuleDiscountCodeUpdate($priceRuleId: ID!, $code: String!) { priceRuleDiscountCodeUpdate(priceRuleId: $priceRuleId, code: $code) { priceRuleUserErrors { field message code } priceRule { id title allocationMethod target validityPeriod { start end } } priceRuleDiscountCode { code } } }",
"variables": {
"priceRuleId": "gid://shopify/PriceRule/1057371214",
"code": "NEWCODE"
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation priceRuleDiscountCodeUpdate($priceRuleId: ID!, $code: String!) {
priceRuleDiscountCodeUpdate(priceRuleId: $priceRuleId, code: $code) {
priceRuleUserErrors {
field
message
code
}
priceRule {
id
title
allocationMethod
target
validityPeriod {
start
end
}
}
priceRuleDiscountCode {
code
}
}
}`,
{
variables: {
"priceRuleId": "gid://shopify/PriceRule/1057371214",
"code": "NEWCODE"
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation priceRuleDiscountCodeUpdate($priceRuleId: ID!, $code: String!) {
priceRuleDiscountCodeUpdate(priceRuleId: $priceRuleId, code: $code) {
priceRuleUserErrors {
field
message
code
}
priceRule {
id
title
allocationMethod
target
validityPeriod {
start
end
}
}
priceRuleDiscountCode {
code
}
}
}`,
"variables": {
"priceRuleId": "gid://shopify/PriceRule/1057371214",
"code": "NEWCODE"
},
},
});
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 priceRuleDiscountCodeUpdate($priceRuleId: ID!, $code: String!) {
priceRuleDiscountCodeUpdate(priceRuleId: $priceRuleId, code: $code) {
priceRuleUserErrors {
field
message
code
}
priceRule {
id
title
allocationMethod
target
validityPeriod {
start
end
}
}
priceRuleDiscountCode {
code
}
}
}
QUERY
variables = {
"priceRuleId": "gid://shopify/PriceRule/1057371214",
"code": "NEWCODE"
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "priceRuleId": "gid://shopify/PriceRule/1057371214",3 "code": "NEWCODE"4}
Response
JSON1{2 "priceRuleDiscountCodeUpdate": {3 "priceRuleUserErrors": [],4 "priceRule": {5 "id": "gid://shopify/PriceRule/1057371214",6 "title": "PROTABO",7 "allocationMethod": "ACROSS",8 "target": "LINE_ITEM",9 "validityPeriod": {10 "start": "2016-08-29T16:00:00Z",11 "end": "2124-09-12T02:11:13Z"12 }13 },14 "priceRuleDiscountCode": {15 "code": "NEWCODE"16 }17 }18}