Obtaining an inventory total for variant using GraphQL

Highlighted
New Member
9 0 0

Thanks for your ongoing support - it is appreciated!

I've had a look at the URL you've suggested, and put together what I think is the right URL based on the values given in the reauthorize OAuth permissions section. I ended up with this:

http://myshopify.com/admin/oauth/authorize?client_id=<MY API KEY>&scope=read_inventory,write_invento...  (I've replaced the key used with text here, to keep it secure!)

This brought up a notification which suggested I needed to go to my shop's domains, and hit Connect to existing domain, then enter myshopify.com - I tried this, but the dashboard complained that it wouldn't accept any domain with Shopify in it, and that my Shopify domain already exists (which it does). I've tried swapping out the API key for the Storefront access token too and included the redirect to point back to my Shopify store - this showed the same issue.

Have I done this right? It feels like I'm going down a rabbit warren (or wrong path - if you pardon the analogy!) I've also tried adding in my domain at the beginning of the URL above, but this threw a invalid_request error: "The Shopify API application does not support oauth". I feel like I'm doing something wrong, and a little bit lost - any chance you could please help me get back on the right track again? 

0 Likes
Highlighted
Shopify Partner
681 47 134

What do you have defined as the redirect_uri in this oauth request? That might be the issue. If you don't have one defined then the GET response will just pop back to the shopify page, which isn't correct. You need to define a redirect_uri. 

Here below are the specifics, taken from the link I provided you. Besides that the first part of the full URL should be https://{my_shop}.myshopify.com where the {my_shop} represents the shop where the app is going to be installed.

 

{redirect_uri}: The URL to which a user is redirected after authorizing the client. The complete URL specified here must be added to your app as an allowed redirection URL, as defined in the Partner Dashboard.

 

0 Likes
New Member
9 0 0

Unfortunately it's not helped, I'm afraid - I tried adding in &redirect-uri=localhost as the domain to my original OAuth URL, as my shop is being run from localhost (as a Gatsby dev application). This threw an error on the "connect domain" screen from before - this time I got "you must enter a full domain and extension". I tried also with havecakeeatcake.myshopify.com, just in case it needed this; it threw the same error as on my previous post...

 

0 Likes
Highlighted
Shopify Partner
2 0 0

`gatsby-source-shopify` - for whatever reason - doesn't give you access to all the GraphQL queries available via the Shopify API, `totalInventory` and `quantityAvailable` being two of these fields. I created an issue to add support for these fields specifically: https://github.com/gatsbyjs/gatsby/issues/26321. As I write this it's been 12 days with no discussion, so I don't expect they will be added any time soon. One work around is you could query the Shopify API directly via REST and not use the gatsby plugin.

0 Likes
Highlighted
New Member
9 0 0

Thank you @abohannon for your help on this - it would be good to have it available via GraphQL if at all possible.

I have had a look at it using REST - I managed to get something working which makes the content available via GraphQL using the gatsby-transformer-json plugin. It's not perfect, as it would require adding a JSON file for updates, but as what I'm doing is something of a POC, it works for now! If you do get any result with the issue report you've filed, I'd be happy to help test if needed

0 Likes
Highlighted
Shopify Partner
681 47 134

It were me, if this Gatsby package is open source I would just download the source, update it to include the missing properties and whatnot, and deploy this updated version for what I need. I've had to do this with similar projects in the past and generally found it easier than working around things other ways. Usually just looking at how the properties are defined for other exposed elements gives a clue how to add new ones. 

0 Likes