What's the best way to get a shopId

Highlighted
Tourist
7 1 1

Hello,

 

I'm building out a nodejs with reactjs front-end for an embedded application and was wondering how would be the best way to get a shopId from the admin?

 

I realize that this request will only work if I have a store's API key and password to make this request: https://apikey:password@<@store_url>/admin/api/2020-07/shop.json

However an embedded application do not have access to the current store's API key and password.

 

Is there another REST endpoint that I can hit to get the shopId?

 

Thank you.

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
140 18 22

Hey @akatcha 

You could take a look into the storefront API which has a shop object to see if that provides the info you need. 

Kevin_A | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

1 Like
Highlighted
Excursionist
38 1 8

You can use Apollo to execute graphql queries from the client (react hooks for or Query tag).

import { useQuery } from '@apollo/react-hooks';
import gql from 'graphql-tag';
...
const GQL=gql`{
  shop {
    contactEmail
  }
}`
...
const {
    loading, error, data,
  } = useQuery(GQL, {
    variables: {
   ...
    },
  });

...

 

https://apps.shopify.com/picamaze
Animated watermarks for product images and ads
1 Like
Highlighted
Shopify Partner
40 3 14

In the initial call to install the app the shop ID is passed as a URL parameter called `shop`. I found one of the easiest things to do was to grab it in the initial call during Oauth and store it in a database.

1 Like
Highlighted
Shopify Partner
40 3 14

Not sure if the above answer helped you or not, or what language you are using, but I created a base app in PHP with no framework or bloat (https://github.com/XenithTech/php-shopify-app-skeleton). Feel free to pick it apart and see how it is all handled. There is one other step I did not mention that could be of an issue to get the `shop` query parameter to where the app is hosted after the Oauth handshake. I took care of this by adding the `shop` URL parameter to my final redirect URL after the handshake was successfully completed. If you have any further issues or questions feel free to ask on here or on GitHub and I will see what I can do for you. If this does help solve the issue, it would be greatly appreciated if you accepted this as the answer for your question.

0 Likes