Discussing Shopify Functions development, deployment, and usage in Shopify apps.
I'm working on creating a Shopify function for creating custom shipping discount codes (Not automatic discounts).
But I get the following error on the checkout screen as soon as the code is applied:
Refresh this page or try again in a few minutes
I followed the standard tutorial to build the discount function but modified it for creating a shipping discount instead: https://shopify.dev/docs/apps/selling-strategies/discounts/experience
Here's the mutation I used to create the discount without any error:
mutation {
discountCodeAppCreate(codeAppDiscount: {
code: "SHIPTEST",
title: "Shipping Test",
functionId: "01H4XPYSZTB3ANV48G0ZEH760M",
startsAt: "2022-06-22T00:00:00"
}) {
codeAppDiscount {
discountId
}
userErrors {
field
message
}
}
}
Here is the input for the function that gets invoked successfully at checkout:
{
"cart": {
"lines": [
{
"quantity": 3,
"merchandise": {
"__typename": "ProductVariant",
"id": "gid://shopify/ProductVariant/45565892690203"
}
}
]
}
}
Here is the output for the function that gets invoked successfully at checkout
{
"discountApplicationStrategy": "FIRST",
"discounts": [
{
"value": {
"percentage": {
"value": 100.0
}
},
"targets": [
{
"deliveryGroup": {
"id": "gid://shopify/CartDeliveryGroup/0"
}
}
],
"message": "100% off"
}
]
}
Now because I see no errors in my dev console, partner's dashboard etc., I have no way to figure out where/what the issue is. Can someone please look into this?
Also including the graphql error as seen in the browser:
[
{
"message": "Internal error. Looks like something went wrong on our end.\nRequest ID: dab38efe-0531-4b2b-8378-6a88b63db1da (include this in support requests).",
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"requestId": "dab38efe-0531-4b2b-8378-6a88b63db1da"
}
}
]
I've also created a Github discussion here if it makes it easier: https://github.com/Shopify/function-examples/discussions/280
Hi Topshop,
It's possible this issue is being caused by an internal server error occurring on Shopify's end when applying the discount code at checkout, which I'm looking into.
In the meantime, there's a couple things you could do to troubleshoot this:
Confirm Functionality: Create a different function that performs a simpler task, such as a simple discount on a product, and apply it to a discount code. If this works, it points towards a specific issue with applying this shipping discount via a Shopify function.
Test the Checkout Flow: Perform tests on your checkout flow. Create different types of discounts, apply them, and proceed to checkout. See if the issue arises with any other discounts or only with the shipping discount.
Validate the Function: Double-check the function and ensure that it's correctly written and follows all necessary guidelines. This includes the structure of the function and its syntax.
If you check these, I'll also look into things on our side so see what might be causing this. Hope this helps,
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
@Liam , I checked the things you'd asked. The function works with the checkout flow without a server error in all other cases. It only seems to have the server error with the shipping function with a CODE (even shipping function with automatic discount works without error).
Hi Topshop - so I've checked this with our product teams and it appears that shipping discount functions aren't currently supported, (although we are working on supporting these).
Hope this helps,
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
@Liam , it shows as being in Developer Preview. Should I wait to develop against it until it's out of preview? Just trying to understand the process. Also, any timelines for when it would be ready to be used would help us plan better.
Hi again Topshop - no timelines to share right now, but keep an eye on the developer changelog here: https://shopify.dev/changelog
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hey Liam, does the Shopify Functions team have an email list I can subscribe to for updates, or is the RSS feed the best way?
Thanks in advance.