cancel
Showing results for 
Search instead for 
Did you mean: 

Posting XML with oData.request

Former Member
0 Kudos

I am trying to POST data, but something is not right , I get error - "no handler for data"

My code is based on this sample : http://scn.sap.com/community/developer-center/front-end/blog/2012/06/06/sample-ume-application-using...

Only difference in POST method is XML content:

OData.request 

               ({  

                         requestUri : "proxy/sap/opu/odata/sap/ZD360_ADD_REMOVE_FAV_SRV/BPartners_Fav",

                          method: "POST",  

                          headers: {  

                                                 "X-Requested-With": "XMLHttpRequest",                        

                                                 "Content-Type": "application/atom+xml;type=enrty",

                                                 "DataServiceVersion": "2.0",  

                                                 "Accept": "application/atom+xml,application/atomsvc+xml,application/xml", 

                                                 "X-CSRF-Token": header_xcsrf_token  

                          },  

                         data:                                                       

                                                       "<entry xmlns='http://www.w3.org/2005/Atom'\                                              xmlns:m='http://schemas.microsoft.com/ado/2007/08/dataservices/metadata'\                                              xmlns:d='http://schemas.microsoft.com/ado/2007/08/dataservices'>\

                                                                                                                               <content type='application/xml'>\

                                                       some content here...

                                                                                                                               </content>\

                                             </entry>"

                       },  

                         function (data, response) 

                         {   alert("Added");    },  

                         function (err)  

                         {  alert("Error adding");  } 

);

Am I specifying XML as Data incorrectly or there is some more info in headers needed ?

Accepted Solutions (0)

Answers (3)

Answers (3)

AshwinDutt
Active Contributor
0 Kudos

Hello Abhinava,

The below are the headers to be set and payload information which might help u :

For XML -> Sample

Headers :

x-csrf-token - Pass the value

Content-Type - application/atom+xml

Payload :

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom"

  xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"

  xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

  <atom:content type="application/xml">

  <m:properties>

  <d:IvManuCompany>0100</d:IvManuCompany>

  <d:RequestNo>TEST_INC</d:RequestNo>

  <d:RequestItmno>0000</d:RequestItmno>

  <d:FromPackage>NZ0025</d:FromPackage>

  <d:ToPackage>NZ0025</d:ToPackage>

  <d:Quantity>1.000</d:Quantity>

  <d:BaseUnit>TON</d:BaseUnit>

  </m:properties>

  </atom:content>

</atom:entry>

For JSON -> Sample

Headers :

x-csrf-token - Pass the value

Content-Type - application/json


Payload :


{

"IvManuCompany":"0100",

"RequestNo":"TEST_IN1",

"RequestItmno":"0001",

"FromPackage":"NZ0025",

"ToPackage":"NZ0025",

"Quantity":"1",

"BaseUnit":"TON"

}

Please note that 500 internal sever error can also because of incorrect format of data which we might be passing inside the payload.

For Example ->

Say u have DATE field and the format we usually pass is like ' 2014-02-02T00:00:00 '. When we don't pass date in this format we get the above error.

So check the format which u r passing as well once.

Regards,

Ashwin

former_member182372
Active Contributor
0 Kudos

well, really, why XML, not JSON? And XML should start with

<?xml version="1.0" encoding="UTF-8"?>

kammaje_cis
Active Contributor
0 Kudos

Hi Maris,

As I understand data cannot be xml, instead it has to be json.

Can you try with json? In teh same blog it says how to send using json.

Thanks

Krishna