Very noob question. Keep getting 'Invalid API key or access token' error

Highlighted
Tourist
4 0 3

Ugh. I feel like such a dork asking, but I want to make a Ruby app that can update some product inventory levels. I can't even get the info of one product. For security, I replaced IDs and passwords with 'foo'.  I'm following the instructions from here: https://github.com/Shopify/shopify_api#shopify-api as best I can.

 

Here's what I have so far:

 

require 'shopify_api'

shop_url = "https://fooID:fooPassword@fooStoreName.myshopify.com"
ShopifyAPI::Base.site = 'https://fooStoreName.myshopify.com'
ShopifyAPI::Base.api_version = "2020-01"

# Get a specific product
product = ShopifyAPI::Product.find(14617660364)

 

 The response from my ruby app is:

9: from RoohApp.ruby:8:in `<main>'

8: from /Library/Ruby/Gems/2.6.0/gems/activeresource-5.1.0/lib/active_resource/base.rb:984:in `find'

7: from /Library/Ruby/Gems/2.6.0/gems/activeresource-5.1.0/lib/active_resource/base.rb:1097:in `find_single'

6: from /Library/Ruby/Gems/2.6.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:85:in `get'

5: from /Library/Ruby/Gems/2.6.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:220:in `with_auth'

4: from /Library/Ruby/Gems/2.6.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:85:in `block in get'

3: from /Library/Ruby/Gems/2.6.0/gems/shopify_api-9.0.2/lib/shopify_api/connection.rb:15:in `request'

2: from /Library/Ruby/Gems/2.6.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:126:in `request'

1: from /Library/Ruby/Gems/2.6.0/gems/shopify_api-9.0.2/lib/shopify_api/connection.rb:7:in `handle_response'

/Library/Ruby/Gems/2.6.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:143:in `handle_response': Failed.  Response code = 401.  Response message = Unauthorized ([API] Invalid API key or access token (unrecognized login or wrong password)). (ActiveResource::UnauthorizedAccess)

 

This curl command works fine, so I don't know why my Ruby app fails:

curl "https://fooID:fooPW@fooStoreName.myshopify.com/admin/shop.json"

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
582 70 127

Hey @RoohBear,

 

It looks like you've replaced the shop_url variable with a string. Try changing  ShopifyAPI::Base.site to shop_url and give it another go. Like this:

require 'shopify_api'

shop_url = "https://fooID:fooPassword@fooStoreName.myshopify.com"
ShopifyAPI::Base.site = shop_url
ShopifyAPI::Base.api_version = "2020-01"

# Get a specific product
product = ShopifyAPI::Product.find(14617660364)

 

 

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Tourist
4 0 3

No, that didn't help but I took your suggestion and added a few more things based on the instructions on GitHub. I get a different error now (some nonsense about a schema not existing);

 

/Library/Ruby/Gems/2.6.0/gems/shopify_api-9.0.2/lib/shopify_api/graphql.rb:25:in `client': Client for API version 2019-01 does not exist because no schema file exists at `shopify_graphql_schemas/2019-01.json`. (ShopifyAPI::GraphQL::InvalidClient)

 

require 'shopify_api'

shop_url = "https://fooID:fooStoreName@foo.myshopify.com"
ShopifyAPI::Base.site = shop_url
ShopifyAPI::Base.api_version = "2020-01"

client = ShopifyAPI::GraphQL.client

SHOP_NAME_QUERY = client.parse <<-'GRAPHQL'
  {
    shop {
      name
    }
  }
GRAPHQL

result = client.query(SHOP_NAME_QUERY)
result.data.shop.name

shop = ShopifyAPI::Shop.current

# Get a specific product
product = ShopifyAPI::Product.find(14617669364)
0 Likes
Highlighted
New Member
3 0 0

I'm having the same issue with invalid client. Did you ever figure it out?

0 Likes
Highlighted
Tourist
4 0 3

No, I lost interest and moved onto a different project.

0 Likes