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'"}]}}]}

