Add email address for discount

availableuser
Visitor
1 0 0

I cannot find documentation that provides an example or work out how to add a customer to a discount code allow list.

 

Known:

  • discount code configured for specific customers
  • email address

Goal:

  • Get or create customer with the email address
  • Add customer to the discount code eligible customer list.

Thank you

Reply 1 (1)

lizk
Shopify Staff
246 58 72

Hi there 👋

Have you tried the discountCodeBasicUpdate mutation? 

//Mutaion
mutation discountCodeBasicUpdate($id: ID!, $basicCodeDiscount: DiscountCodeBasicInput!) {
  discountCodeBasicUpdate(id: $id, 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
    }
  }
}
// Variables
{
  "id": "gid://shopify/DiscountCodeNode/1234",
  "basicCodeDiscount": {
    "customerSelection": {
      "customers": {
        "add": ["gid://Shopify/Customer/1234"]
      }
    }
    }
  }

 

To learn more visit the Shopify Help Center or the Community Blog.