Http access in order-discount extensions.

Solved

Http access in order-discount extensions.

fehmianac
Shopify Partner
2 0 0

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

 

 

 

 

 

 

Accepted Solution (1)

tobebuilds
Shopify Partner
589 42 159

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.

Founder, Regios Discounts app (4.8 stars, 93 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer
- Often imitated, never duplicated

View solution in original post

Replies 2 (2)

tobebuilds
Shopify Partner
589 42 159

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.

Founder, Regios Discounts app (4.8 stars, 93 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer
- Often imitated, never duplicated
fehmianac
Shopify Partner
2 0 0

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.