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.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Problem making a discount for one customer

Solved

Problem making a discount for one customer

mwolfeu_pi3g
Shopify Partner
5 1 1

With the example query giving free shipping here (also attached below): https://shopify.dev/docs/api/admin-graphql/2023-07/mutations/discountCodeFreeShippingCreate

I how would I modify it to apply to one customer: "gid://shopify/Customer/12345" ?

 

Thanks in advance!

 

 

 

{
  data: {
    "query": `mutation discountCodeFreeShippingCreate($freeShippingCodeDiscount: DiscountCodeFreeShippingInput!) {
      discountCodeFreeShippingCreate(freeShippingCodeDiscount: $freeShippingCodeDiscount) {
        codeDiscountNode {
          id
          codeDiscount {
            ... on DiscountCodeFreeShipping {
              title
              startsAt
              endsAt
              maximumShippingPrice {
                amount
              }
              customerSelection {
                ... on DiscountCustomerAll {
                  allCustomers
                }
              }
              destinationSelection {
                ... on DiscountCountryAll {
                  allCountries
                }
              }
              minimumRequirement {
                ... on DiscountMinimumSubtotal {
                  greaterThanOrEqualToSubtotal {
                    amount
                  }
                }
              }
              codes(first: 2) {
                nodes {
                  code
                }
              }
            }
          }
        }
        userErrors {
          field
          code
          message
        }
      }
    }`,
    "variables": {
      "freeShippingCodeDiscount": {
        "startsAt": "2022-06-22T21:12:07.000Z",
        "appliesOncePerCustomer": false,
        "title": "FreeShipping",
        "code": "FreeShipping",
        "minimumRequirement": {
          "subtotal": {
            "greaterThanOrEqualToSubtotal": 20.0
          }
        },
        "customerSelection": {
          "all": true
        },
        "destination": {
          "all": true
        }
      }
    },
  },
}
Accepted Solution (1)

lizk
Shopify Staff
246 58 79

This is an accepted solution.

Hi there 👋

You would want to modify the variables to specify which customers you want this discount code to apply to. 

It should look something like this.

{
  "freeShippingCodeDiscount": {
    "startsAt": "2022-06-22T21:12:07.000Z",
    "appliesOncePerCustomer": false,
    "title": "FreeShipping",
    "code": "FreeShipping",
    "minimumRequirement": {
      "subtotal": {
        "greaterThanOrEqualToSubtotal": 20
      }
    },
    "customerSelection": {
      "customers": {
        "add": ["gid://shopify/Customer/1234567"]
      }
    },
    "destination": {
      "all": true
    }
  }
}

 

If you are not already using it, I would recommend using the Shopify GraphiQL app. It has autocomplete so it can be helpful when modify queries.

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

View solution in original post

Reply 1 (1)

lizk
Shopify Staff
246 58 79

This is an accepted solution.

Hi there 👋

You would want to modify the variables to specify which customers you want this discount code to apply to. 

It should look something like this.

{
  "freeShippingCodeDiscount": {
    "startsAt": "2022-06-22T21:12:07.000Z",
    "appliesOncePerCustomer": false,
    "title": "FreeShipping",
    "code": "FreeShipping",
    "minimumRequirement": {
      "subtotal": {
        "greaterThanOrEqualToSubtotal": 20
      }
    },
    "customerSelection": {
      "customers": {
        "add": ["gid://shopify/Customer/1234567"]
      }
    },
    "destination": {
      "all": true
    }
  }
}

 

If you are not already using it, I would recommend using the Shopify GraphiQL app. It has autocomplete so it can be helpful when modify queries.

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