App reviews, troubleshooting, and recommendations
Hello everyone,
I want to build order-discount plugin for shopify. I need to get discount configuration from my application via http request. But i am unable to use fetch in run function.
Is there a possible way to handle it?
export function run(input: RunInput): FunctionRunResult {
//get the configuration from the external api call
const configuration: Configuration = JSON.parse(
input?.discountNode?.metafield?.value ?? "{}"
);
fetch("https://api.github.com/users/hadley/orgs").then((res) => {
//GET discount configuration from external api
});;
return {
discountApplicationStrategy: DiscountApplicationStrategy.Maximum,
discounts: [
{
value: {
percentage: {
value: 5
}
},
conditions: [
{
orderMinimumSubtotal: {
minimumAmount: 1000,
targetType: TargetType.OrderSubtotal,
excludedVariantIds: []
}
}
],
targets: [
{
orderSubtotal: {
excludedVariantIds: []
}
}
],
message: "5% off"
},
{
value: {
percentage: {
value: 10
}
},
targets: [
{
orderSubtotal: {
excludedVariantIds: []
}
}
],
message: "10% off"
}
]
};
};
Solved! Go to the solution
This is an accepted solution.
Functions can't access the Internet.
You need to store the discount configuration as a metafield on the discount node you create, and then query that configuration as part of the input variables to your function.
This is an accepted solution.
Functions can't access the Internet.
You need to store the discount configuration as a metafield on the discount node you create, and then query that configuration as part of the input variables to your function.
Thank Tobebuilds.
We have saas marketing suit, So we just need to build shopify app to integrate our marketing platform.
Thank you again your answer.
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025