Discount for amount Graphql

Hello to everyone,
i’m findig problem with the code for the discount. i’m tryin to get two differnt tipe:

by percentage
by amount

by percentage

percentage the code is working:

“query”: “mutation CreateSummerDiscount($input: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $input) { codeDiscountNode { id codeDiscount { … on DiscountCodeBasic { title codes(first: 10) { nodes { code } } startsAt endsAt } } } userErrors { field message } } }”,
“variables”: {
“input”: {
“title”: “edoardo2”,
“code”: “BUYNOW200”,
“startsAt”: “2025-01-21T00:00:00Z”,
“endsAt”: “2025-02-21T00:00:00Z”,
“customerSelection”: {
“all”: true
},
“customerGets”: {
“value”: {
“percentage”: 0.2
},
“items”: {
“all”: true
}
},
“appliesOncePerCustomer”: true
}
}
}’

but by amout it doesn’t.

“query”: “mutation CreateSummerDiscount($input: DiscountCodeBasicInput!) { discountCodeBasicCreate(basicCodeDiscount: $input) { codeDiscountNode { id codeDiscount { … on DiscountCodeBasic { title codes(first: 10) { nodes { code } } startsAt endsAt } } } userErrors { field message } } }”,
“variables”: {
“input”: {
“title”: “edoardo2”,
“code”: “BUYNOW200”,
“startsAt”: “2025-01-21T00:00:00Z”,
“endsAt”: “2025-02-21T00:00:00Z”,
“customerSelection”: {
“all”: true
},
“customerGets”: {
“value”: {
“amount”: 100
},
“items”: {
“all”: true
}
},
“appliesOncePerCustomer”: true
}
}
}’

any suggest help?

Thanks

this is the error message

{
“errors”: [{
“message”: “Variable $input of type DiscountCodeBasicInput! was provided invalid value for customerGets.value.amount (Field is not defined on DiscountCustomerGetsValueInput)”,
“locations”: [{
“line”: 1,
“column”: 31
}],
“extensions”: {
“value”: {
“title”: “edoardo2”,
“code”: “BUYNOW200”,
“startsAt”: “2025-01-21T00:00:00Z”,
“endsAt”: “2025-02-21T00:00:00Z”,
“customerSelection”: {
“all”: true
},
“customerGets”: {
“value”: {
“amount”: 0.2
},
“items”: {
“all”: true
}
},
“appliesOncePerCustomer”: true
},
“problems”: [{
“path”: [“customerGets”, “value”, “amount”],
“explanation”: “Field is not defined on DiscountCustomerGetsValueInput”
}]
}
}]

Hey,

The error tells you what is wrong with your query, that the field “amount” doesn’t exist on “value” in the “customerGets” object on your input to the query.

You can see in the docs the allowed inputs and format discountCodeBasicCreate - GraphQL Admin

I believe you are looking for “discountAmount”.

The graphql errors and docs are pretty clear on what you can and cannot do :slight_smile:

Thanks for your reply , already try even with ` “customerGets”: {
“value”: {
“discountAmount”:20
},

but i don’t see any difference

`

Do you receive any errors back?

1 Like

tahnks for your suggest I resolve with “customerGets”: {
“value”: {
“discountAmount”: {
“amount”: 20.00,
“appliesOnEachItem”: false
}