I am following this tutorial https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react/embed-your-app-in-shopify I am able to run application and all the steps are working fine for me. Now if I want to test my application on some shopify store which is live on production then is it possible to install my custom application and test it? I have requested my client’s to give me access to shopify store and they have accepted my request. Now while installing the custom application I cannot see my client’s shopify store why so?
The old way of installing unlisted public apps has been removed by Shopify.
If you want to test your app on a production store, you’ll have to duplicate your app and when you’re creating the app in Shopify’s partner dashboard select “custom app” and use this option
If I want to access any shopify store data then can I make use of this package https://github.com/Shopify/shopify-node-api I have already created custom app on store and shopify store as well on partner dashboard. So now if I want to fetch products via Admin API then can I use above package? Also one more question can I use same package to access data of any other shopify store if the owner of that shopify store has already added me as a collaborator to that shopify store?
I have setup everything as mentioned in docs but not able to perform OAuth using shopify node-express. Once OAuth is successful I want to create session and then make different routes to fetch data from shopify store via Admin API’s
code snippet:
// src/index.ts
import express from 'express';
import Shopify, { ApiVersion, AuthQuery } from '@shopify/shopify-api';
require('dotenv').config();
const app = express();
const { API_KEY, API_SECRET_KEY, SCOPES, SHOP, HOST } = process.env;
Shopify.Context.initialize({
API_KEY,
API_SECRET_KEY,
SCOPES: [SCOPES],
HOST_NAME: HOST,
IS_EMBEDDED_APP: true,
API_VERSION: ApiVersion.April21 // all supported versions are available, as well as "unstable" and "unversioned"
});
app.get('/login', async (req, res) => {
let authRoute = await Shopify.Auth.beginAuth(req, res, SHOP, '/auth/callback', true);
return res.redirect(authRoute);
})
app.get('/auth/callback', async (req, res) => {
try {
await Shopify.Auth.validateAuthCallback(req, res, req.query as unknown as AuthQuery); // req.query must be cast to unkown and then AuthQuery in order to be accepted
} catch (error) {
console.error(error); // in practice these should be handled more gracefully
}
return res.redirect('/'); // wherever you want your user to end up after OAuth completes
});
app.get('/getproducts', async (req, res) => {
const session = await Shopify.Utils.loadCurrentSession(req, res);
console.log("session", session)
// Create a new client for the specified shop.
const client = new Shopify.Clients.Rest(session.shop, session.accessToken);
// Use `client.get` to request the specified Shopify REST API endpoint, in this case `products`.
const products = await client.get({
path: 'products',
});
console.log("session", session)
console.log("client", client)
console.log("products", products)
});
app.listen(3000, () => {
console.log('your app is now listening on port 3000');
});
In above code it is saying shop of undefined which means session is not created. I think I am doing some wrong in OAuth process. Can you please let me know what I am doing wrong in above code?
With above code setup if I go to {your ngrok address}/login route (in browser) then I see 302 in ngrok terminal. Next I go to this route {your ngrok address}/auth/callback (in browser). After that I go to {your ngrok address}/oauth/begin now it gives me error in nodejs terminal:
CookieNotFound [Error]: Cannot complete OAuth process. Could not find an OAuth cookie for shop url: undefined
How should I solve this issue? Any suggestions/idea?
Ok then I will also go with standard approach instead of using some shopify npm packages. I want to generate access token for admin API’s I was following this article https://shopify.dev/tutorials/authenticate-with-oauth in step 2 they have mentioned redirect_uri but I have general question this redirect_uri will always change when ngrok is refreshed so how will it work exactly? How can I generate access token for admin API’s in such cases? I am following this article https://shopify.dev/docs/admin-api/getting-started in that X-Shopify-Access-Token is required. If you don’t mind can I contact you on skype?
I followed your suggestion duplicating the app and generated a new single-merchant-link, the generation of the link is successful but when I try to use it on a new store, it redirect me to “Example Domain.com” instead of the install page.
Is it a bug in the link generation or there is some restriction that I’m not aware of?