shashank verma
shashank verma

Reputation: 21

sending xml data using post request

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

Upvotes: 1

Views: 16213

Answers (2)

Venkatesh Bachu
Venkatesh Bachu

Reputation: 2553

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

Upvotes: 4

Chandan
Chandan

Reputation: 766

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?

Upvotes: 1

Related Questions