Development discussions around Shopify APIs
Hi I am following https://www.sitepoint.com/shopify-app-development-made-simple/ tutorial.
I have obtained access token and stored it in database after install the app goes to myapp page.
Lets say user has already installed the app and goes to my app . How can I get the shop name in my embedded app so I can get its accesstoken and perform requests.
Since the app already is in iframe and to get access token from database I have to use shop name but how can I get that in iframe ?
You should see a GET request and its parameters. One of the parameters is the shop name.
In the tutorial, it's done in the following line:
1. $query = $_GET;
2. $store = $query['shop'];
So $store is the shop name.
Thanks a lot Felix !
There is no good php api for detailed stuff support is good only for ruby on rails . I had figued this by checking there were iframe parameters but it good to be confident about things from a official person !
Hello Zack,
just as a side note: I'm not an employee or "official person" of shopify.
if (isset($_SERVER['HTTP_REFERER'])) { $referalUrl = $_SERVER['HTTP_REFERER']; $qs = parse_url($referalUrl, PHP_URL_QUERY); if (!empty($qs)) { parse_str($qs, $output); print_r($output); $shop = preg_replace('/.myshopify.com$/', '', $output['shop']); //get store name without fullurl // TODO check for key existence $_SESSION['shop'] = $shop; } }
This code will return shop name everytime you logged in. Hope this will help anyone. This code works for me.
$_SESSION['shop'] = $_GET['shop'];
works for first time only. When you logged in after logout, it doesnot return any value.
Hey so to get the shop if ur using the next.js boilerplate code from shopify-cli
go to pages -> _app.js, u'll get it in the ctx.query object in the getInitialProps method so just return it
MyApp.getInitialProps = async ({ ctx }) => {
return {
host: ctx.query.host,
shop: ctx.query.shop
};
};
now u should be able to access it from props of MyApps class
class MyApp extends App {
render() {
const { Component, pageProps, host, shop } = this.props;
return (
<AppProvider i18n={translations}>
<Provider
config={{
apiKey: API_KEY,
host: host,
forceRedirect: true,
}}
>
<MyProvider Component={Component} shop={shop} {...pageProps} />
</Provider>
</AppProvider>
);
}
}
User | RANK |
---|---|
50 | |
11 | |
8 | |
6 | |
6 |
Thanks to all who participated in our AMA with 2H Media on planning your 2023 marketing bu...
By Jacqui Mar 30, 2023Thanks to all Community members that participated in our inaugural 2 week AMA on the new E...
By Jacqui Mar 10, 2023Upskill and stand out with the new Shopify Foundations Certification program
By SarahF_Shopify Mar 6, 2023