Headless commerce and custom storefronts with Shopify APIs and SDKs
To continue receiving payouts, you need to secure your account by turning on two-step authentication. If two-step authentication is not turned on your payouts will be paused. Learn more
Im making a private App that applies a discount to the Checkout.
Im have to use the Stroefront API since private Apps cant get
var discountUrl = TestStoreURL + '/api/graphql.json';
var base64Id = Buffer.from(id.toString()).toString('base64');
const checkoutQuery = `
mutation checkoutDiscountCodeApplyV2($discountCode: String!, $checkoutId: ID!) {
checkoutDiscountCodeApplyV2(discountCode: $discountCode, checkoutId: $checkoutId) {
checkout {
id
}
checkoutUserErrors {
code
field
message
}
}
}
{
checkoutId: ` + base64Id + `,
discountCode: ` + discountCode + `
}
`;
const results = await fetch(discountUrl, {
method: 'POST',
uri: discountUrl,
headers : {
'X-Shopify-Storefront-Access-Token' : SHOPIFY_ACCESS_STOREFRONT_TOKEN_TEST,
'Accept': 'application/json, text/plain, ',
'Content-Type': 'application/json'
},
body : JSON.stringify(checkoutQuery)
})
.then(response => response.json())
.then(json => {
log.info(json);
});
permisson for the Checkout scope of the Admin API.
So im trying to use the checkoutDiscountCodeApplyV2 mutation. But im always getting errors: 'Parameter Missing or Invalid' and no futher information.
Here is the relevant code:
You likely need to pass the variables and query separately when using fetch.
const checkoutQuery = `
mutation checkoutDiscountCodeApplyV2($discountCode: String!, $checkoutId: ID!) {
checkoutDiscountCodeApplyV2(discountCode: $discountCode, checkoutId: $checkoutId) {
checkout {
id
}
checkoutUserErrors {
code
field
message
}
}
}
`;
body: JSON.stringify({
query: checkoutQuery,
variables: {
checkoutId: base64Id,
discountCode
}
})
Thanks for your reply I changed my code according to your suggestion and the variables are now send correctly.
Im currently sending the checkoutId as such:
Buffer.from('gid://shopify/Checkout/'+id.toString()).toString('base64');
But i get the following Error as a response:
{
code: 'INVALID',
field: [ 'checkoutId' ],
message: 'Checkout existiert nicht'
}
And i get the checkout if directly from the ctx.request.body.id.
Do you might know why i cant find the checkout?.
Do i hve to use the Checkout update instead of the Checkout creation webhook?
Learn these 5 things I had to learn the hard way with starting and running my own business
By Kitana Jan 27, 2023Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022