Different graphql query responses, postman vs. graphql shopify app vs. node shopify-buy plugin

Solved
Excursionist
16 2 0

I cannot imagine why this is happening. Entering the exact same query into the shopify graphql app returns all 5 products (just fake products for test purposes, two different vendors, which should not matter???) but I am submitting queries with postman, AND the Shopify GraphiQL App, AND by node plugin shopify-buy

 but no matter WHAT I DO (I have tried changing EVERY POSSIBLE THING) the queries to postman and shopify-buy will only return two of the five products that are in my shop. The Shopify GraphiQL App shows me everything in my shop, all five products. graphql-shopify.pngpostman-shopify.png

What is this? Why is this happening? I am beginning to think the universe does not want me to learn how to make Shopify apps. 😫😭

0 Likes

Success.

Shopify Staff
Shopify Staff
268 36 38

Hey @ACrego,

 

Using the Admin GraphQL API (https://{shop}.myshopify.com/admin/api/graphql.json), you'll have access to all products published on all channels/apps.

 

Using the Storefront API (https://{shop}.myshopify.com/api/graphql) with a Storefront access token, you'll only have access to products published to that specific app.

 

Your Postman screenshot appears to be hitting the Storefront API (and will only show some products), whereas the Shopify GraphiQL App uses the Admin API (which will show all products).

 

In contrast with the Admin API, which enables developers to build apps around merchant-facing actions (such as shipping and fulfillment), the Storefront API focuses on shopping experiences seen from the customer perspective.

 

0 Likes
Excursionist
16 2 0

Thank you! 

 

Finally! It is clear! :D

0 Likes
Excursionist
16 2 0

OK wait, I'm confused again. 

 

How many different types of authorization are there? There's storefront, I know how to use, and then there's admin, which requires this - "https://<api-key>:<password>@test-store.myshopify.com/admin/api/2019-07/graphql.json " type of authentication, with the query in the POST body, but when do you need the OAuth token? 

 

Because right now, I'm trying the admin api URL with the key:password from my private app, sending a super simple query in a POST request using postman, and I'm getting a 200 response back but it's just a html with a redirect url on the page that doesn't go anywhere, it doesn't work. 

0 Likes

Success.

Shopify Staff
Shopify Staff
268 36 38

Hey @ACrego,

 

Shopify uses OAuth to issue access tokens on behalf of users. This is useful when building public apps.

 

Since you're building a private app:

 

To authenticate with the Storefront API you can use the storefront access token in a request header:

 

X-Shopify-Storefront-Access-Token: <storefront-access-token>

 

21-11-2oqef-4z61m

 

To authenticate with the Admin API you can use the generated API password in a request header:

 

X-Shopify-Access-Token: <api-password>

 

21-19-ndiuu-h9750

1 Like
Excursionist
16 2 0

Ok, wow, really, it's that simple? Everything else is the same, just the name of the header is slightly different and the token is different? That is amazing! 

I'm going to go try it right now! 

0 Likes
Excursionist
16 2 0

Please help me understand something. 

 

Do Private and Public Apps both have access to GraphQL data? Is there a limit to how much of the data or which type of data is available, depending on whether it is private or public, or is the type of API used (GraphQL or REST) going to make more of a difference? 

 

I think I just want to make a private app, but I want to be able to query all the data relevant to a store; i.e., get ALL the products, not just two of them. I also want to use the cart checkout functionality. Is this in scope?  

 

It seems I cannot just add /admin to the url and use the token as you showed me. I'm getting CORS errors, and investigating that turns up that I need OAuth authentication, proxy, redirect url, etc., and I don't have an outside app to make a request with. 

0 Likes

Success.

Shopify Staff
Shopify Staff
268 36 38

To clarify the differences between the Admin API and the Storefront API:

 

The Admin API, which is available in REST and GraphQL, lets you build apps and other integrations for the Shopify admin. For example, you might want to look through old orders or update products programmatically.

 

If you want to create Shopify-powered storefronts for platforms outside of the Shopify admin, including websites, mobile apps, and game development engines, then see the Storefront API instead. The Storefront API is an unauthenticated public API.

 

I also want to use the cart checkout functionality.

It sounds like you're after the Storefront API.

 

get ALL the products, not just two of them

You can control which apps/channels have access to which products in the admin:

 

23-14-of51o-w82e1

 

Regarding Storefront API rate limits, there's more information here.

1 Like
Excursionist
16 2 0

OH MY GOD!

 

:D

 

This is what I needed to know! Thank you!

 

I started this nightmare rabbit hole all because I was only seeing two of my five test products, and somebody told me it was because of the API, which honestly didn't make sense why it would limit the number of items, (as opposed to http requests) but I'm just learning, so what do I know? 

 

So now I have updated all of my products, they were indeed inconsistent; some of them had only one of the two apps available. 

 

Do I understand correctly, storefront is actually all I need for an app (that I can use in any web app) (would this considered a "private app"?) with shopping cart and checkout functionality? That is great news, I have no problems getting storefront apps to work, and the product configuration should solve the last small issue there.

 

NOW, still, because I'm stubborn, lol, I'd really truly still like to understand how the admin API works, since I've spent SO MUCH TIME trying to get it working. 

 

I went completely all the way through the React + Node tutorial, only to discover that it results in an embedded app, which is definitely not what I am after.

 

I have not tried the Node + Express example yet, maybe that's the one I want. 

It's for mac os only!  😭😭😭

 

I've been teaching myself programming for a couple of years, (embarrassingly long for how bad I still am!) but I'm beginning to realize that I am sort of lost in this seemingly desert wasteland in between front end and back end. I can build an app with a mySQL or other similar database back end, or I can build a React/Javascript/etc. app front end, but this (admin) API stuff is making me crazy! 

 

 

0 Likes
Shopify Staff
Shopify Staff
268 36 38

Yeah that can be confusing! Sounds like you're on the right path now.

 

Do I understand correctly, storefront is actually all I need for an app with shopping cart and checkout functionality?

That's right. Good luck with the journey!

1 Like