I created shopify public app using yarn create @Shopify/app. I get nodejs code template will oAuth process and session token. Following is the API that i created in shopify public app.
Now when I call this API in postman I get the following error
I am unable to find out that how to give shop name and where do I get shop name and access_token? And I wanted to ask that is it possible to call API which is created in shopify public app in other software? It would act as a third party integration. Kindly someone guide me.
Unfortunately, the express Shopify App isn't like your usual Express apps. When a customer installs your app they are identified and stored as a "session" inside your database. As you can see the error that came back "No Shop Provided".
The "shop" and other information are provided by the fronted. Underneath the hood, the "frontend" there is code to add the shop and also a security Authorization header, a "Bearer" token useAuthenticatedFetch.js.
And so on the frontend code, it may look simple, ProductsCard.jsx:
const response = await fetch("/api/products/create");
Unfortunately, the bearer token keys off a timestamp, the time stamp does expire and so you'll need to quickly generate the token and copy-paste it into postman.
Edited: I found the answer, the answer was right in front of our faces. Sorry I didn't see this before.
// If you are adding routes outside of the /api path, remember to
// also add a proxy rule for them in web/frontend/vite.config.js
I was working on a route called /dogs
. I added dogs in the web/frontend/vite.config.js
# web/frontend/vite.config.js
proxy: {
"^/(\\?.*)?$": proxyOptions,
"^/api(/|(\\?.*)?$)": proxyOptions,
"^/dogs(/|(\\?.*)?$)": proxyOptions,
Then on the server side I was able to add /dogs
app.use(express.urlencoded({ extended: true }));
app.use("/api/*", shopify.validateAuthenticatedSession());
app.use("/dogs", dogRoutes);
Now I was able to hit the route easily without authentication issues such as Shop null