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"
}
]
};
};