Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

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

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)