2
votes

I'm working on a private Shopify application. I'm trying to get this resource (from Shopify endpoint):

https://store.myshopify.com/admin/products.json

using Net::HTTP library in this way:

url = 'https://'+@api_key+':'+@password+'@storename.myshopify.com/admin/products.json' 
uri = URI(url)  
response = Net::HTTP.get(uri) 
p = JSON.parse(response)

But what I get is:

=> {"errors"=>"[API] Invalid API key or access token (unrecognized login or wrong password)"}

What is the correct way to get resources from Shopify admin endpoints?

1
Maybe I should use another authentication method? - Mr. L
Try passing the api key and api pass using header encoded by base64 - HymnZzy
@HymnZ, thanks for your reply! Indeed, as I understand, the method I used above (through basic HTTP authorization) is not longer supported. There are many plugins/gems out there that allow authorization with API like: shopify_app gem , omniauth-shopify-oauth2, Postman , JWT and so on. I'm just lost in this sea of variants. Also I couldn't find any articles about how properly use them. Can you suggest some tool to use? Or post some link to explanation about how to perform API calls to admin endpoints using header encoded by base64? - Mr. L

1 Answers

0
votes

Ok, so I found the solution for my problem. For anyone who doesn't know how to access Admin Shopify API endpoints (for example: /admin/products.json?collection_id=841564295) which requires authentication, you may use 'Postman' Chrome App.

Here is the tutorial of how to use it.

Most importantly is that Postman (from its UI) generates a code for you in number of languages (including in Ruby). enter image description here So this is how you use it. Just copy-paste this code into your Rails application and don't forget to add require 'OpenSSL' coz the Postman some how doesn't include this line in the generated code.