I'm trying to write a Python script to make an Amazon purchase using the Zinc API (see: https://zinc.io/docs/#full-api). I should be able to do this through a single POST request, so I read up about urllib and urllib2 here.
However, when I run my script, I receive this error:
{"_type":"error","code":"invalid_json","message":"The JSON in your request could not be parsed."}
I'm following Zinc's code pretty precisely, so I'm not sure why I'm getting the error.
Here is what I'm running (Note: my personal information is excluded, but included when I run the script):
import urllib
import urllib2
import json
url = 'https://api.zinc.io/v0/order'
values = {"client_token" : "public",
"retailer" : "amazon",
"products" :[{"product_id" : "0679753354", "quantity" : 1}],
"max_price" : 1700, "shipping_address" : {
"first_name" : "NAME",
"last_name" : "NAME",
"address_line1" : "ADDRESS",
"address_line2" : "",
"zip_code" : "ZIP",
"city" : "CITY",
"state" : "STATE",
"country" : "US"
},
"is_gift" : False,
"shipping_method" : "cheapest",
"payment_method" : {
"name_on_card" : "NAME",
"number" : "CARDNUMBER",
"security_code" : "SECCODE",
"expiration_month" : 1,
"expiration_year": 2015
},
"billing_address" : {
"first_name" : "NAME",
"last_name" : "NAME",
"address_line1" : "ADDRESS",
"address_line2" : "",
"zip_code" : "ZIP",
"city" : "CITY",
"state" : "STATE",
"country" : "US",
"phone_number" : "PHONE"
},
"retailer_credentials" : {
"email" : "EMAIL",
"password" : "PASSWORD"}
}
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()
print the_page
Any ideas on how to fix this JSON parsing issue would be much appreciated, as I haven't been able to figure out what's wrong.