New Shopify Certification now available: Liquid Storefronts for Theme Developers

How to get shop name and accessToken during oAuthProcess

Solved
Faateh
Shopify Partner
12 0 0

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
Shopify Staff
1671 235 344

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
Shopify Staff
1671 235 344

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
12 0 0

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

SBD_
Shopify Staff
Shopify Staff
1671 235 344

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

Scott | Developer Advocate @ Shopify 

Faateh
Shopify Partner
12 0 0

Thank you!