Getting "401 Unauthorized" for shopify_api:graphql:dump on custom app

pascallaliberte
Tourist
5 0 1

If you find yourself getting a "401 Unauthorized" error when trying to do a schema dump for the GraphQL API, and you've got a custom app, the following instructions are confusing:

Dumps a local JSON schema file of the Shopify Admin API. The schema is specific to an
API version and authentication is required (either OAuth or private app).

Dump the schema file for the 2020-01 API version using private app authentication:
  $ rake shopify_api:graphql:dump SHOP_URL="https://API_KEY:PASSWORD@SHOP_NAME.myshopify.com" API_VERSION=2020-01

Dump the schema file for the unstable API version using an OAuth access token:
  $ rake shopify_api:graphql:dump SHOP_DOMAIN=SHOP_NAME.myshopify.com ACCESS_TOKEN=abc API_VERSION=unstable


What about a custom app? Not a private app, not a public app...

So you might be trying to do this:

bin/rails shopify_api:graphql:dump SHOP_URL="https://SHOPIFY_API_KEY:SHOPIFY_API_SECRET@SHOP_NAME.myshopify.com" API_VERSION=2020-10

 

And then getting this:

Fetching schema for 2020-10 API version...
Error: failed to query the API.
Response: {"errors"=>[{"message"=>"401 Unauthorized"}]}

 

Apparently the SHOPIFY_API_KEY and the SHOPIFY_API_SECRET weren't what you needed to use. Instead, we need to find out the OAuth key that's stored in the app's database for the Shop.

# bin/rails console

> shop = Shop.find_by shopify_domain: "SHOP_NAME.myshopify.com"
> shop.shopify_token
=> "shpca_**********************************"


That shpca_ is the token to use:

bin/rails shopify_api:graphql:dump ACCESS_TOKEN=shpca_**************************** SHOP_DOMAIN="SHOP_NAME.myshopify.com" API_VERSION=2020-10

 

That should do the trick. Hope that helps!

Reply 1 (1)

Al1_andre
Tourist
8 1 2

Thank you soooooooo much.