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
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",
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-07/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
JSON{
"priceRuleId": "gid://shopify/PriceRule/1057371214",
"code": "NEWCODE"
}
Response
JSON{
"priceRuleDiscountCodeUpdate": {
"priceRuleUserErrors": [],
"priceRule": {
"id": "gid://shopify/PriceRule/1057371214",
"title": "PROTABO",
"allocationMethod": "ACROSS",
"target": "LINE_ITEM",
"validityPeriod": {
"start": "2016-08-29T16:00:00Z",
"end": "2124-09-12T02:11:13Z"
}
},
"priceRuleDiscountCode": {
"code": "NEWCODE"
}
}
}