Hi, I’m trying to develop a shopify admin app to export merchant’s orders in a format compatible with our application, so I need to call admin api.
I’m trying to install the app using shopify/app-bridge as explained here https://help.shopify.com/en/api/embedded-apps/app-bridge/oauth, but every time, after installation, shopify redirect on my website outside the iframe.
This is my code;
const redirectUri = "https://xxxx.ngrok.io/shopify-auth";
var urlParams = new URLSearchParams(window.location.search);
var shopOrigin = urlParams.get('shop');
const permissionUrl = `/oauth/authorize?client_id=${apiKey}&scope=read_products,read_content&redirect_uri=${redirectUri}`;
if (window.top == window.self) {
window.location.assign(`https://${shopOrigin}/admin${permissionUrl}`)
} else {
const app = createApp({
apiKey: apiKey,
shopOrigin: shopOrigin,
forceRedirect: true
});
console.log('bridge redirect')
Redirect.create(app).dispatch(Redirect.Action.ADMIN_PATH, permissionUrl);
}
https://xxx.ngrok.io/shopify-auth****:
var urlParams = new URLSearchParams(window.location.search);
var code = urlParams.get('code');
var shop = urlParams.get('shop');
Here I can get the code and I can call my server that call the
https://shopname.myshopify.com/admin/oauth/access_token
to get the access_token and call the admin api, but at this point I’m out of shopify iframe.
Can anyone help me?
I can be more clear if needed.
Thanks,
regards
Davide