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.

Re: How to get shop name and accessToken during oAuthProcess

Solved

How to get shop name and accessToken during oAuthProcess

Faateh
Shopify Partner
17 0 1

I am trying to get access token and shopName from latest shopify app embedded code template.
 Here is the following code

Screenshot from 2023-07-03 18-03-55.png

How would I get it when someone installs my app?

Accepted Solution (1)

SBD_
Shopify Staff
1831 273 423

This is an accepted solution.

Hey @Faateh 

Access token is part of the session:

 

const { accessToken } = res.locals.shopify.session;

 

And the shop name can be obtained like this:

 

const { data } = await shopify.api.rest.Shop.all({
  session: res.locals.shopify.session,
})
console.log(data[0].name);

 

Scott | Developer Advocate @ Shopify 

View solution in original post

Replies 4 (4)

SBD_
Shopify Staff
1831 273 423

This is an accepted solution.

Hey @Faateh 

Access token is part of the session:

 

const { accessToken } = res.locals.shopify.session;

 

And the shop name can be obtained like this:

 

const { data } = await shopify.api.rest.Shop.all({
  session: res.locals.shopify.session,
})
console.log(data[0].name);

 

Scott | Developer Advocate @ Shopify 

Faateh
Shopify Partner
17 0 1

@SBD_ will this access token be same for life time?

SBD_
Shopify Staff
1831 273 423

Yep, unless your app is uninstalled or you revoke the access token.

Scott | Developer Advocate @ Shopify 

Faateh
Shopify Partner
17 0 1

Thank you!