Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I'm trying to use the GQL to create at discount code for a specific cusotmer. I was succesful in using the provided template code in the link below to add a discount code for all customers. But when I modify it I get a "Invalid global id" Error.
Documentation:
https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/discountCodeBasicCreate
Here are my variables
This is the customer id I'm using to test.
I'm using the provided template mutation code from the documentation:
query = '''
mutation discountCodeBasicCreate($basicCodeDiscount: DiscountCodeBasicInput!) {
discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {
codeDiscountNode {
codeDiscount {
... on DiscountCodeBasic {
title
codes(first: 10) {
nodes {
code
}
}
startsAt
endsAt
customerSelection {
... on DiscountCustomerAll {
allCustomers
}
}
customerGets {
value {
... on DiscountPercentage {
percentage
}
}
items {
... on AllDiscountItems {
allItems
}
}
}
appliesOncePerCustomer
}
}
}
userErrors {
field
code
message
}
}
}
'''
Error response:
{"errors":[{"message":"Variable $basicCodeDiscount of type DiscountCodeBasicInput! was provided invalid value for customerSelection.customers.add.0 (Invalid global id '7929561841982')","locations":[{"line":2,"column":34}],"extensions":{"value":{"title":"test3","code":"test3","startsAt":"2022-06-21T00:00:00Z","endsAt":"2022-09-21T00:00:00Z","customerSelection":{"all":false,"customers":{"add":[7929561841982]}},"customerGets":{"value":{"percentage":0.2},"items":{"all":true}},"appliesOncePerCustomer":true},"problems":[{"path":["customerSelection","customers","add",0],"explanation":"Invalid global id '7929561841982'","message":"Invalid global id '7929561841982'"}]}}]}
I finally got it to work. The fix was that the customer input was not correct it should be formated like this:
"customerSelection": {
'customers': {
'add': ['gid://shopify/Customer/7936674496830']
}
},
customerSelection {
... on DiscountCustomerAll {
allCustomers
}
... on DiscountCustomers {
customers {
id
firstName
lastName
email
}
}
}
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025