1

http://api.shipstation.com/Order-Resource.ashx

Above URL is shipstation API document for fetching order,creating orders,updating and deleting.

I want to use create order API which is POST request ,where order data entries are sent to shipstation using xml.

My question is how i can send xml data to shipstation using POST request using Python?

Since iam not able to post entire code on this page ,so please refer this URL to see post request for creating order-

http://api.shipstation.com/Order-Resource.ashx

Thanks

shashank verma
  • 21
  • 1
  • 2
  • 5

2 Answers2

4

you should try like this

def frame_xml(AddressVerified,AmountPaid):
    xml_data = """<?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"  xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/ metadata" xmlns="http://www.w3.org/2005/Atom">
    <category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" term="SS.WebData.Order" />
     <title />
     <author>
     <name />
     </author>
     <id />
     <content type="application/xml">
     <m:properties>
       <d:AddressVerified m:type="Edm.Byte">%s</d:AddressVerified>
       <d:AmountPaid m:type="Edm.Decimal">%s</d:AmountPaid>
     </m:properties>
    </content>
   </entry>"""%(AddressVerified,AmountPaid)
   return xml_data

headers = {'Content-Type': 'application/xml'}
xml_data = frame_xml('AddressVerified','AmountPaid')
print requests.post('https://data.shipstation.com/1.2/Orders', data=xml_data, headers=headers).text
Venkatesh Bachu
  • 2,348
  • 1
  • 18
  • 28
1

Use Python requests module. Some examples you can find on quick-start page:

>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.post("http://httpbin.org/post", data=payload)
>>> print r.text
    ...

Or

>>> url = 'http://httpbin.org/post'
>>> files = {'file': open('report.xls', 'rb')}

>>> r = requests.post(url, files=files)
    ...

See more here: How can I send an xml body using requests library?

Community
  • 1
  • 1
Chandan
  • 746
  • 6
  • 8
  • shipstation API have headers too like POST https://data.shipstation.com/1.2/Orders HTTP/1.1 User-Agent: Microsoft ADO.NET Data Services DataServiceVersion: 1.0;NetFx MaxDataServiceVersion: 2.0;NetFx Accept: application/atom+xml,application/xml Accept-Charset: UTF-8 Content-Type: application/atom+xml Host: data.shipstation.com Content-Length: 4213 Expect: 100-continue Connection: Keep-Alive so how to put header in above code? – shashank verma Feb 04 '14 at 10:44
  • 1
    requests.post('http://httpbin.org/post', data=xml, headers=headers). See more here http://stackoverflow.com/questions/12509888/how-can-i-send-an-xml-body-using-requests-library – Chandan Feb 04 '14 at 10:55