Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
Hey All,
I am trying to create discount codes programmatically in a shopify store, but am running into an interesting result. When you create a discount code in your shop manually they appear like this
which is how I would like my programmatically created codes to appear. However, when i create them using the graphql admin api, they appear like this
notice how in the first image, it lists the code you created and says "Customers will enter this discount code at checkout" whereas the second image says "Each customer will enter a unique code at checkout" I do not want each customer to have to enter a unique code at checkout. There is no usage limit restriction on the code created programmatically so i am not sure why it says this message.
The query I am using is
`mutation discountCodeBasicCreate($basicCodeDiscount: DiscountCodeBasicInput!) {
discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {
userErrors {
field
message
}
codeDiscountNode {
id
codeDiscount {
... on DiscountCodeBasic {
title
summary
status
codes(first: 10) {
edges {
node {
code
}
}
}
}
}
}
}
}
`
and the attributes i am passing are
attributes: {
basicCodeDiscount: {
appliesOncePerCustomer: true,
code: {some code },
customerGets: { items: {array_of_prod_ids}, value:{ percentage : 0.15 },
customerSelection: {
all: true,
},
endsAt: {some end date},
minimumRequirement: {
quantity: { greaterThanOrEqualToQuantity: 1},
},
startsAt: {some start date},
title: {some title},
usageLimit: null,
},
},
};
i am following the example as shown in the docs at https://shopify.dev/api/admin-graphql/2021-07/mutations/discountcodebasiccreate yet all my codes look as though they are creating one time use codes or something like that? Im honestly not sure what else it could mean by saying "Each customer will enter a unique code at checkout". Anyways I basically want to be able to create codes from my app that can be used by however many customers.
I seen your post and you have mentioned discount code are different. So I request to you please use Shopify Admin API because it will be get exact information in which you needed.
The codes that are different are being created via the Admin API...