App reviews, troubleshooting, and recommendations
I've gone through the documentation on creating a store-specific custom app, but when I get to the part where I query for the product count, I get the error:
2023-03-16 20:59:46 | backend | /Users/elias/Desktop/zenvy-app/web/node_modules/@shopify/shopify-api/lib/clients/rest/rest_client.js:15 2023-03-16 20:59:46 | backend | throw new ShopifyErrors.MissingRequiredArgument('Missing access token when creating REST client');
Here's how I've configured my shopifyApp:
const shopify = shopifyApp({ api: { apiVersion: LATEST_API_VERSION, restResources, billing: undefined, }, auth: { path: "/api/auth", callbackPath: "/api/auth/callback", }, webhooks: { path: "/api/webhooks", }, sessionStorage: new SQLiteSessionStorage(DB_PATH), apiKey: process.env.APP_API_KEY, apiVersion: LATEST_API_VERSION, apiSecretKey: process.env.ADMIN_API_ACCESS_TOKEN, isCustomStoreApp: true, scopes: [ 'write_customers', 'write_products' ], isEmbeddedApp: false, hostName: process.env.HOST_NAME, restResources, });
To get to the above configuration, I first generated the project from npm init @shopify/app@latest app. Then I added additional fields according to the creating a store-specific custom app documentation. As you can see, I have set the apiSecretKey to my Admin API access token (NOT the API secret key), so I'm not sure why it's not working. Also note that I've tried logging all the `process.env` fields, and they are all correctly configured.
Also just FYI, I noticed that the documentation is partially out-of-date. The line:
const session = shopify.session.customAppSession("my-shop.myshopify.com");
should be:
const session = shopify.api.session.customAppSession("my-shop.myshopify.com");
And same for the `shopify.rest` commands, where it should be `shopify.api.rest`
Anyone know how I can resolve the error I am experiencing?
Thanks,
Elias
Solved! Go to the solution
This is an accepted solution.
Actually, it turns out the problem was the tutorial was meant for instantiating a shopifyApi
, not a shopifyApp
. To instantiate a shopifyApp
, I needed to add the configuration parameters into the api
object. Here's how I've now configured my shopifyApp
:
const shopify = shopifyApp({
api: {
apiVersion: LATEST_API_VERSION,
restResources,
billing: undefined,
apiKey: process.env.APP_API_KEY,
apiSecretKey: process.env.ADMIN_API_ACCESS_TOKEN,
isCustomStoreApp: true,
scopes: [
'write_customers',
'write_products'
],
isEmbeddedApp: false,
hostName: process.env.HOST_NAME,
},
auth: {
path: "/api/auth",
callbackPath: "/api/auth/callback",
},
webhooks: {
path: "/api/webhooks",
},
sessionStorage: new SQLiteSessionStorage(DB_PATH),
});
And that's why the documentation had the line correct as the below, since shopify
referred to shopifyApi
, not shopifyApp
:
const session = shopify.session.customAppSession("my-shop.myshopify.com");
I was able to figure it out! It turns out you need to move some of the configuration parameters into the api
object. Here's how I've now configured my shopifyApp:
const shopify = shopifyApp({
api: {
apiVersion: LATEST_API_VERSION,
restResources,
billing: undefined,
isCustomStoreApp: true,
apiKey: process.env.APP_API_KEY,
apiSecretKey: process.env.ADMIN_API_ACCESS_TOKEN,
},
auth: {
path: "/api/auth",
callbackPath: "/api/auth/callback",
},
webhooks: {
path: "/api/webhooks",
},
sessionStorage: new SQLiteSessionStorage(DB_PATH),
scopes: [
'write_customers',
'write_products'
],
isEmbeddedApp: false,
hostName: process.env.HOST_NAME,
});
It would be great if someone could update the documentation to reflect this new required format.
This is an accepted solution.
Actually, it turns out the problem was the tutorial was meant for instantiating a shopifyApi
, not a shopifyApp
. To instantiate a shopifyApp
, I needed to add the configuration parameters into the api
object. Here's how I've now configured my shopifyApp
:
const shopify = shopifyApp({
api: {
apiVersion: LATEST_API_VERSION,
restResources,
billing: undefined,
apiKey: process.env.APP_API_KEY,
apiSecretKey: process.env.ADMIN_API_ACCESS_TOKEN,
isCustomStoreApp: true,
scopes: [
'write_customers',
'write_products'
],
isEmbeddedApp: false,
hostName: process.env.HOST_NAME,
},
auth: {
path: "/api/auth",
callbackPath: "/api/auth/callback",
},
webhooks: {
path: "/api/webhooks",
},
sessionStorage: new SQLiteSessionStorage(DB_PATH),
});
And that's why the documentation had the line correct as the below, since shopify
referred to shopifyApi
, not shopifyApp
:
const session = shopify.session.customAppSession("my-shop.myshopify.com");
User | RANK |
---|---|
7 | |
4 | |
4 | |
4 | |
4 |
Thanks 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, 2023One of the key components to running a successful online business is having clear and co...
By Ollie Mar 6, 2023