Hello,
I’ve been struggling with this for a while now, and I’ve given up and come here for help.
The use case:
In a different program we have a long list of of customers, each customer have a pricelist (some customers may share a pricelist). Each pricelist may contain prices for items that will likely be different than the regular salesprice.
We want to transfer this logic to Shopify using the API.
The goal is to have this discounted price apply automatically. Now it’s my understanding that discounts can only be shown during checkout, is this correct?
Anyway to the problem(s). I’m going to describe the issues and put in my queries as I go a long, in hopes someone can spot any errors/missing properties. All queries gets sent to admin/api/2024-07/graphql.json
First, I tried to create Pricerules through the rest API - this did what what I wanted, mostly. I could make the discount apply for a specific item for a specific customer - however, I could not get it be automatic, it would default to require discount codes - which would defeat the entire purpose.
I then discovered you could add discount through GRaphQL - but also pricerules, so I modified my query to graphGL, but had the same result. It wouldn’t be automatic.
Pricerule mutation:
mutation priceRuleCreate($priceRule: PriceRuleInput!) {
priceRuleCreate(priceRule: $priceRule) {
priceRule {
id
title
target
allocationMethod
startsAt
endsAt
oncePerCustomer
customerSelection {
forAllCustomers
}
itemEntitlements {
targetAllLineItems
}
}
userErrors {
field
message
}
}
}
And the variables with identifiers replaced:
{
"priceRule": {
"allocationMethod": "EACH",
"customerSelection": {
"forAllCustomers": false,
"customerIdsToAdd": [
"gid://shopify/Customer/123456"
]
},
"itemEntitlements": {
"productVariantIds": [
"gid://shopify/ProductVariant/123456"
]
},
"target": "LINE_ITEM",
"title": "Here is my discount3",
"validityPeriod": {
"end": "2024-09-07T15:50:00Z",
"start": "2023-09-07T15:50:00Z"
},
"value": {
"fixedAmountValue": "-10"
}
}
}
Now the internet (and ChatGPT) tells me that if I define usage_limit to be null, it would be automatic, but that doesn’t change anything.
Am I missing something here?
Next step in this journey, was discovering discountAutomaticBasicCreate - this allowed me to create automatic discounts, but there doesn’t seem to be any way to create a discount for a specific customer - similar to how discounts are created manually in the backend.
Again, I’m adding my query in hopes, there may be something wrong there.
My mutation:
mutation discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) {
discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBasic {
startsAt
endsAt
minimumRequirement {
... on DiscountMinimumQuantity {
greaterThanOrEqualToQuantity
}
}
customerGets {
value {
... on DiscountAmount {
amount {
amount
currencyCode
}
appliesOnEachItem
}
}
items {
... on AllDiscountItems {
allItems
}
}
}
}
}
}
userErrors {
field
code
message
}
}
}
And my variables:
{
"automaticBasicDiscount": {
"title": "$50 off all orders over $200 during the summer of 2022",
"startsAt": "2022-06-21T00:00:00Z",
"endsAt": "2024-09-21T00:00:00Z",
"minimumRequirement": {
"quantity": {
"greaterThanOrEqualToQuantity": "1"
}
},
"customerGets": {
"value": {
"discountAmount": {
"amount": 50,
"appliesOnEachItem": false
}
},
"items": {
"all": false,
"products": {
"productVariantsToAdd": [
"gid://shopify/ProductVariant/40151273177174"
]
}
}
}
}
}
Does Shopify simply not have this functionality or am I missing something?