New Shopify Certification now available: Liquid Storefronts for Theme Developers

perfroming a Graphql API request and perfoming oauth on the backend of my app.

lantaarnpaal1
Shopify Partner
1 0 1

Hello,

 

I am building a app and it needs to fetch the stores data when the merchant is outside of the app. I wrote a fetch module but it is responding with HTML code. I think something is wrong with the oAuth as the token is not even passed into the fetch(). Here is the code. Is it even possible to fetch api data on the background? I cannot use 'appBridge' or authenticatedFetch as these are unsupported modules. 

 

Thank you for reading.

 

 

 

 

 

function fetching() {
const appOrigin = 'mystore';

return async (uri, options) => {
const response = await fetch(
uri.startsWith("/")
? `https://${appOrigin}/apps${uri}`
: `https://${appOrigin}/apps/${uri}`,
options
);

const url = `https://${appOrigin}/apps${uri}`;
console.log(url);
const reauthorizeHeader = response.headers.get("X-Shopify-API-Request-Failure-Reauthorize");
if (reauthorizeHeader === "1") {
const authUrlHeader = response.headers.get("X-Shopify-API-Request-Failure-Reauthorize-Url");
window.location = authUrlHeader || '/exitframe';
return null;
}

return response;
};
}

 

 

 

 

Replies 0 (0)