Skip to Content
avatar image
Former Member

OData create request body malformed

Hello everyone,

i am currently developing an SAPUI5 application which is accessing an OData service exposed by Java Olingo framework. The odata service is fine and i am also able to retrieve entities from the the service. However, i am still struggling to insert something.

I have one entity Customer with two nagivation properties to Title and Country. In the SAPUI5 i create the payload as follows:

var payload = {
  ID: nID,
  CDate: new Date(), 
  UDate: new Date(), 
  CustomerNumber: customer.CustomerNumber, 
  Prename: customer.Prename, 
  Surname: customer.Surname, 
  Birth: customer.Birth, 
  PhoneNumber: customer.PhoneNumber, 
  FaxNumber: customer.FaxNumber, 
  Street: customer.Street, 
  StreetNumber: customer.StreetNumber, 
  AdditionalText: customer.AdditionalText, 
  ZipCode: customer.ZipCode, 
  City: customer.City
  };
 
  payload.Title = {
  __metadata: {
  uri: this.getView().byId("selectTitle").getSelectedItem().getBindingContext().getPath()
  }
  };
  payload.Country = {
  __metadata: {
  uri: this.getView().byId("selectCountry").getSelectedItem().getBindingContext().getPath()
  }
  }; 

  console.log(JSON.stringify(payload));
  var oData = this.getODataModel();

  oData.create("/Customer", payload, null,
  jQuery.proxy(this.onCreateSuccessPopUp, this), 
  jQuery.proxy(this.onCreateFailPopUp, this));

The resulting payload in Json looks as follows:

{

"ID":0,

"CDate":"2015-10-15T15:45:19.176Z",

"UDate":"2015-10-15T15:45:19.176Z",

"CustomerNumber":"54433422",

"Prename":"Test",

"Surname":"Test",

"Birth":"2015-10-14T22:00:00.000Z",

"PhoneNumber":"123456789",

"Street":"Test",

"StreetNumber":"14",

"ZipCode":"50126",

"City":"Bergheim",

"Title":{"__metadata":{"uri":"/Title(1L)"}},

"Country":{"__metadata":{"uri":"/Country(1L)"}

}}

The error from the odata looks as follows:

HTTP request failed400,Bad Request,{"error":{"code":null,"message":{"lang":"en","value":"The request body is malformed."}}}

Somebody know how to fix it? For the OData object i tried both version (v2.ODataModel and ODataModel).

Hope somebody can help me.

Thanks

Best regards,

Manjinder Singh

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Oct 16, 2015 at 04:20 PM

    Hello everyone,

    i solved the problem. I used __deferred instead of __metadata. Furthermore, i have to cut the first character (/) from the path.

    1. payload.Title = {
    2. __deferred: {
    3. uri: this.getView().byId("selectTitle").getSelectedItem().getBindingContext().getPath().substring(1)
    4. }
    5. };
    6. payload.Country = {
    7. __deferred: {
    8. uri: this.getView().byId("selectCountry").getSelectedItem().getBindingContext().getPath() .substring(1)
    9. }

    Best regards,

    Manjinder Singh

    Add comment
    10|10000 characters needed characters exceeded