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
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": {
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/2025-01/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
JSON{
"id": "gid://shopify/DiscountCodeNode/206265824",
"basicCodeDiscount": {
"endsAt": null,
"code": "NEW_CODE",
"appliesOncePerCustomer": true,
"customerGets": {
"value": {
"percentage": 0.4
}
}
}
}
Response
JSON{
"discountCodeBasicUpdate": {
"codeDiscountNode": {
"id": "gid://shopify/DiscountCodeNode/206265824"
},
"userErrors": []
}
}