import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) {
discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBasic {
title
startsAt
combinesWith {
productDiscounts
shippingDiscounts
orderDiscounts
}
minimumRequirement {
... on DiscountMinimumSubtotal {
greaterThanOrEqualToSubtotal {
amount
currencyCode
}
}
}
customerGets {
value {
... on DiscountAmount {
amount {
amount
currencyCode
}
}
}
items {
... on AllDiscountItems {
allItems
}
}
}
}
}
}
userErrors {
field
code
message
}
}
}`,
{
variables: {
"automaticBasicDiscount": {
"title": "$10 off orders over $100 (combinable with shipping discounts)",
"startsAt": "2025-07-24T16:19:41-04:00",
"minimumRequirement": {
"subtotal": {
"greaterThanOrEqualToSubtotal": "100.00"
}
},
"customerGets": {
"value": {
"discountAmount": {
"amount": "10.00",
"appliesOnEachItem": false
}
},
"items": {
"all": true
}
},
"combinesWith": {
"productDiscounts": false,
"shippingDiscounts": true,
"orderDiscounts": false
}
}
},
},
);
const json = await response.json();
return json.data;
}