Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Create discount code with no customers

Solved

Create discount code with no customers

thealiaguy
Shopify Partner
4 0 2

Hi there. I'm trying to create an empty basic discount code (one with no customers), and then add customers as necessary. But when I try to create such a discount code using the discountCodeBasicCreate mutation, I get the error "Customer selection a minimum of one prerequisite segment or prerequisite customer must be provided". Is there any way to create a discount code with no customers and add them later as necessary? 

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1453 238 524

This is an accepted solution.

Hey @thealiaguy - thanks for getting in touch, this is a great question. At the moment, you do need to set a specific custom segment or customer in order to create a discount code. That said, one workaround you can use is setting the customer segment to every customer by using the "all" field  in the customerSelection array to have the discount apply to every customer. If you don't want the discount to be active right away, you could then set the "startsAt" date to some time in the future. Once you know which customers or customer segments you'd like to apply to the discount code, you can use the discountCodeBasicUpdate mutation to change the customer array's values. Here's an example snippet of the values you could use to set the discount code up (assigning it to all customers and setting a date in the future to prevent its use):

{
 "basicCodeDiscount": {
   "title": "Al's Discount",
   "code": "AL20",
   "startsAt": "2023-06-21T00:00:00Z",
   "endsAt": "2023-09-21T00:00:00Z",
   "customerSelection": {
     "all": true
   },
   "customerGets": {
     "value": {
       "percentage": 0.2
     },
     "items": {
       "all": true
     }
   },
   "appliesOncePerCustomer": true
 }
}

 

Hope this helps - let us know if we can clarify anything further on our end. 

Al | Shopify Developer Support 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1453 238 524

This is an accepted solution.

Hey @thealiaguy - thanks for getting in touch, this is a great question. At the moment, you do need to set a specific custom segment or customer in order to create a discount code. That said, one workaround you can use is setting the customer segment to every customer by using the "all" field  in the customerSelection array to have the discount apply to every customer. If you don't want the discount to be active right away, you could then set the "startsAt" date to some time in the future. Once you know which customers or customer segments you'd like to apply to the discount code, you can use the discountCodeBasicUpdate mutation to change the customer array's values. Here's an example snippet of the values you could use to set the discount code up (assigning it to all customers and setting a date in the future to prevent its use):

{
 "basicCodeDiscount": {
   "title": "Al's Discount",
   "code": "AL20",
   "startsAt": "2023-06-21T00:00:00Z",
   "endsAt": "2023-09-21T00:00:00Z",
   "customerSelection": {
     "all": true
   },
   "customerGets": {
     "value": {
       "percentage": 0.2
     },
     "items": {
       "all": true
     }
   },
   "appliesOncePerCustomer": true
 }
}

 

Hope this helps - let us know if we can clarify anything further on our end. 

Al | Shopify Developer Support 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog