Skip to main content

draftOrderCreate and draftOrderUpdate require the apply_discounts_to_draft_orders permission to add discounts

In all supported API versions, draftOrderCreate and draftOrderUpdate return an ACCESS_DENIED error when an app acting as a staff member without the apply_discounts_to_draft_orders permission adds a discount to a draft order. The mutations don’t save the draft order and return null for the mutation payload. Apps that rely only on userErrors for failure handling need to update their error handling.

What changed

When a request runs as a staff member who doesn’t have the apply_discounts_to_draft_orders permission draftOrderCreate and draftOrderUpdate reject any change that adds discounts through the DraftOrderInput:

  • Adding a discount code to discountCodes that the draft order doesn’t already have
  • Setting acceptAutomaticDiscounts to true on a draft order that doesn’t already accept automatic discounts

For draftOrderCreate any non-empty discountCodes or acceptAutomaticDiscounts: true counts as adding a discount because the draft order doesn’t exist yet.

In these cases, the mutation returns a top-level GraphQL error with the code ACCESS_DENIED and null for the mutation’s payload. The error doesn’t appear in userErrors.

Keeping or removing a draft order’s existing discounts still works.

Example

This request adds a discount code and turns on automatic discounts for an existing draft order:

mutation draftOrderUpdate($id: ID!, $input: DraftOrderInput!) {
draftOrderUpdate(id: $id, input: $input) {
draftOrder {
id
discountCodes
acceptAutomaticDiscounts
}
userErrors {
field
message
}
}
}
{
"id": "gid://shopify/DraftOrder/276395349",
"input": {
"discountCodes": ["SUMMER10"],
"acceptAutomaticDiscounts": true
}
}

If the staff member doesn't have the apply_discounts_to_draft_orders permission, the response is:

{
"errors": [
{
"message": "Access denied for draftOrderUpdate field. Required access: `write_draft_orders` access scope. Also: The user must have access to manage draft orders.",
"locations": [{ "line": 2, "column": 3 }],
"path": ["draftOrderUpdate"],
"extensions": {
"code": "ACCESS_DENIED",
"documentation": "https://shopify.dev/api/usage/access-scopes",
"requiredAccess": "`write_draft_orders` access scope. Also: The user must have access to manage draft orders."
}
}
],
"data": {
"draftOrderUpdate": null
}
}

draftOrderCreate returns the same error, with draftOrderCreate in the message and path, and null for data.draftOrderCreate.

Who's affected

You’re affected if your app:

  • Calls draftOrderCreate or draftOrderUpdate as a staff member, and
  • Expects to add discount codes or enable automatic discounts, and
  • Doesn’t ensure that the staff member has the apply_discounts_to_draft_orders permission

Requests that don’t act as a staff member, such as requests made with an offline access token, aren’t affected.

What to do

  1. Check the top-level errors array, not just userErrors, for an ACCESS_DENIED error from draftOrderCreate or draftOrderUpdate.
  2. If your app needs to add discounts, ask the merchant to give the staff member the Apply discounts permission under Draft orders.

Related docs

Was this page helpful?