Exception: Mutation had errors: "Variable $id of type ID! was provided invalid value"

That’s the error i’m getting with a discountCodeBasicUpdate admin API request. Here is my input:

{
  "basicCodeDiscount": {
    "title": "{{ order.name }}",
    "appliesOncePerCustomer": true,
    "code": "{{ order.name }}",
    "usageLimit": 1,
    "context": {
      "customers": {
        "add": [
          "{{ order.customer.id }}"
        ]
      }
    },
    "customerGets": {
      "value": {
        "discountAmount": {
          "amount": "25.00",
          "appliesOnEachItem": false
        }
      },
      "items": {
        "products": {
          "productsToAdd": [
            "gid://shopify/Product/9617924784413"
          ]
        },
        "all": false
      },
      "appliesOnOneTimePurchase": true,
      "appliesOnSubscription": false
    }
  }
}

Here’s the actual input in the run:

{
  "mutation_name": "discountCodeBasicUpdate",
  "mutation_input": "{\n  \"basicCodeDiscount\": {\n    \"title\": \"#292491\",\n    \"appliesOncePerCustomer\": true,\n    \"code\": \"#292491\",\n    \"usageLimit\": 1,\n    \"context\": {\n      \"customers\": {\n        \"add\": [\n          \"gid://shopify/Customer/7789058687261\"\n        ]\n      }\n    },\n    \"customerGets\": {\n      \"value\": {\n        \"discountAmount\": {\n          \"amount\": \"25.00\",\n          \"appliesOnEachItem\": false\n        }\n      },\n      \"items\": {\n        \"products\": {\n          \"productsToAdd\": [\n            \"gid://shopify/Product/9617924784413\"\n          ]\n        },\n        \"all\": false\n      },\n      \"appliesOnOneTimePurchase\": true,\n      \"appliesOnSubscription\": false\n    }\n  }\n}",
  "api_version": "2026-01",
  "hydration_type_patch": "{}"
}

Where’s the discount GID?

Hey @ctevan

Two issues with your setup:

  1. You’re using discountCodeBasicUpdate but not passing the id of the existing discount. Based on your input (new code, title, usage limit), it looks like you want to create a discount, so switch to discountCodeBasicCreate.

  2. The context.customers field isn’t valid on DiscountCodeBasicInput. Customer eligibility goes under customerSelection.

Here’s your corrected input for discountCodeBasicCreate:

{
  "basicCodeDiscount": {
    "title": "{{ order.name }}",
    "appliesOncePerCustomer": true,
    "code": "{{ order.name }}",
    "usageLimit": 1,
    "customerSelection": {
      "customers": {
        "add": [
          "{{ order.customer.id }}"
        ]
      }
    },
    "customerGets": {
      "value": {
        "discountAmount": {
          "amount": "25.00",
          "appliesOnEachItem": false
        }
      },
      "items": {
        "products": {
          "productsToAdd": [
            "gid://shopify/Product/9617924784413"
          ]
        },
        "all": false
      },
      "appliesOnOneTimePurchase": true,
      "appliesOnSubscription": false
    }
  }
}

Just swap the mutation to discountCodeBasicCreate and this should work straight away.

Best,
Moeed