Anchor to discountCodeBasicUpdatediscount
discountCodeBasicUpdate
mutation
Requires Apps must have access scope.
Updates an amount off discount that's applied on a cart and at checkout when a customer enters a code. Amount off discounts can be a percentage off or a fixed amount off.
Anchor to Arguments
Arguments
- Anchor to basicCodeDiscountbasic•
Code Discount DiscountCode requiredBasic Input! The input data used to update the discount code.
- •ID!required
The ID of the discount code to update.
Was this section helpful?
Anchor to DiscountCodeBasicUpdatePayload returnsDiscountCodeBasicUpdatePayload returns
- Anchor to codeDiscountNodecode•
Discount Node The discount code that was updated.
- Anchor to userErrorsuser•
Errors [DiscountUser non-nullError!]! The list of errors that occurred from executing the mutation.
Was this section helpful?
- Update a basic code discount
- Update a discount code to apply to specific products
- discountCodeBasicUpdate reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation discountCodeBasicUpdate($id: ID!, $basicCodeDiscount: DiscountCodeBasicInput!) {6 discountCodeBasicUpdate(id: $id, basicCodeDiscount: $basicCodeDiscount) {7 codeDiscountNode {8 id9 }10 userErrors {11 field12 code13 message14 }15 }16 }`,17 {18 variables: {19 "id": "gid://shopify/DiscountCodeNode/206265824",20 "basicCodeDiscount": {21 "endsAt": null,22 "code": "NEW_CODE",23 "appliesOncePerCustomer": true,24 "customerGets": {25 "value": {26 "percentage": 0.427 }28 }29 }30 },31 },32);3334const data = await response.json();35
mutation discountCodeBasicUpdate($id: ID!, $basicCodeDiscount: DiscountCodeBasicInput!) {
discountCodeBasicUpdate(id: $id, basicCodeDiscount: $basicCodeDiscount) {
codeDiscountNode {
id
}
userErrors {
field
code
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 discountCodeBasicUpdate($id: ID!, $basicCodeDiscount: DiscountCodeBasicInput!) { discountCodeBasicUpdate(id: $id, basicCodeDiscount: $basicCodeDiscount) { codeDiscountNode { id } userErrors { field code message } } }",
"variables": {
"id": "gid://shopify/DiscountCodeNode/206265824",
"basicCodeDiscount": {
"endsAt": null,
"code": "NEW_CODE",
"appliesOncePerCustomer": true,
"customerGets": {
"value": {
"percentage": 0.4
}
}
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation discountCodeBasicUpdate($id: ID!, $basicCodeDiscount: DiscountCodeBasicInput!) {
discountCodeBasicUpdate(id: $id, basicCodeDiscount: $basicCodeDiscount) {
codeDiscountNode {
id
}
userErrors {
field
code
message
}
}
}`,
{
variables: {
"id": "gid://shopify/DiscountCodeNode/206265824",
"basicCodeDiscount": {
"endsAt": null,
"code": "NEW_CODE",
"appliesOncePerCustomer": true,
"customerGets": {
"value": {
"percentage": 0.4
}
}
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation discountCodeBasicUpdate($id: ID!, $basicCodeDiscount: DiscountCodeBasicInput!) {
discountCodeBasicUpdate(id: $id, basicCodeDiscount: $basicCodeDiscount) {
codeDiscountNode {
id
}
userErrors {
field
code
message
}
}
}`,
"variables": {
"id": "gid://shopify/DiscountCodeNode/206265824",
"basicCodeDiscount": {
"endsAt": null,
"code": "NEW_CODE",
"appliesOncePerCustomer": true,
"customerGets": {
"value": {
"percentage": 0.4
}
}
}
},
},
});
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 discountCodeBasicUpdate($id: ID!, $basicCodeDiscount: DiscountCodeBasicInput!) {
discountCodeBasicUpdate(id: $id, basicCodeDiscount: $basicCodeDiscount) {
codeDiscountNode {
id
}
userErrors {
field
code
message
}
}
}
QUERY
variables = {
"id": "gid://shopify/DiscountCodeNode/206265824",
"basicCodeDiscount": {
"endsAt": null,
"code": "NEW_CODE",
"appliesOncePerCustomer": true,
"customerGets": {
"value": {
"percentage": 0.4
}
}
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "id": "gid://shopify/DiscountCodeNode/206265824",3 "basicCodeDiscount": {4 "endsAt": null,5 "code": "NEW_CODE",6 "appliesOncePerCustomer": true,7 "customerGets": {8 "value": {9 "percentage": 0.410 }11 }12 }13}
Response
JSON1{2 "discountCodeBasicUpdate": {3 "codeDiscountNode": {4 "id": "gid://shopify/DiscountCodeNode/206265824"5 },6 "userErrors": []7 }8}