Hi, I'm having trouble adding a product with a Ruby script. I'm building an uploaded plugin for Dropzone.
I'm new to Ruby so I'm not quite sure how to format the post request with the api credentials. In my code I have the correct credentials instead of "apikey", "password", and "myshopname".
require 'net/http'
require "rexml/document"
include REXML # so that we don't have to prefix everything with REXML::...
doc = Document.new '<?xml version="1.0" encoding="UTF-8"?><product/>'
root = doc.root
type = root.add_element "product-type"
body = root.add_element "body"
title = root.add_element "title"
tags = root.add_element "tags"
vendor = root.add_element "vendor"
sku = root.add_element "sku"
type.text = "Art Print"
body.text = "Body text"
title.text = "Title text"
tags.text = "animal,water"
vendor.text = "My name"
sku.text = "123456"
shopify_url = 'https://apikey:password@myshopname.myshopify.com/admin/products.xml'
url = URI.parse(shopify_url)
request = Net::HTTP::Post.new(url.path)
request.content_type = 'text/xml'
request.body = doc
response = Net::HTTP.start(url.host) {|http| http.request(request)}
puts response
Response I'm getting is a "500 - Temporary Problem".
Thanks!
... View more