Problem making a discount for one customer

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
        }
      }
    },
  },
}

Hi there :waving_hand:

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.