Mr. L Mr. L - 1 year ago 138
JSON Question

How to GET /admin/products.json (from Shopify API Endpoint) using Rails

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

library in this way:

url = 'https://'[email protected]_key+':'[email protected]+''
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 endpoints?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download