I spent a lot of time struggling trying to get my shopify private connection working.
For those of you who are also new to rails and shopify and are stuck at this point this is how I did it.
First of all go to your shop->apps->manage apps
and set up a Private app and look for your api_key and password you will need those to authenticate your connection.
Now let's take a look at an example code that asks for products.xml using the API
require 'net/https'
api = "your-api"
password = "your-password"
http = Net::HTTP.new('yourshop.myshopify.com')
#http.use_ssl = true (We do not need to use SSL)
http.start do |http|
req = Net::HTTP::Get.new('/admin/products.xml')
# we have to authenticate our
# username and password
req.basic_auth api, password
resp, data = http.request(req) #data will be the xml returned by the server
end
Basically you need to use an authenticated connection, to do this I used the Net:HTTP module on ruby.
No comments:
Post a Comment