Skip to Content
0

Create Operation using ODataModel.create Method

Sep 02, 2017 at 01:06 AM

60

avatar image

Hi,

I am trying to use create method, but i am getting 400 Bad Request with response "Error while parsing an XML stream" in response.

Request header are: -

Accept: application/json

Accept-Encoding: gzip, deflate, br

Accept-Language: en-US

Connection: keep-alive

Content-Length: 351

Content-Type: application/json

Cookie: Webstorm-ce54f5f5=8852077a-9d11-49d7-8c2b-3638b1e31b63; sap-usercontext=sap-client=333; SAP_SESSIONID_ECG_333=CzA8f_T7DgutTJDU-J4QmTCM3VOL7hHngPIAUFapOUA%3d

DataServiceVersion: 2.0

Host: localhost:65189

MaxDataServiceVersion: 2.0

Origin: http://localhost:65189

Referer: http://localhost:65189/Consumption_History/index.html

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36

x-csrf-token: 43GoArn3EwBPQIPfLU3LOQ==

Request Payload is : -

Consumption:"12"

DeviceID:"NOP0004144"

MeterReadingCategoryID:"01"

MeterReadingNoteID:"12"

MeterReadingReasonID:"01"

MeterReadingResultID:""

MeterReadingStatusID:"4"

MultipleMeterReadingReasonsFlag:"false"

ReadingDateTime:"2015-04-16T13:40:00"

ReadingResult:"12"

ReadingUnit:"KVA"

RegisterID:"004"

SerialNumber:"NOP0004144"

Can you please suggest.

Thanks,
Shrikant.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Akhilesh Upadhyay Sep 02, 2017 at 05:37 PM
0

Hi,

you can check your datatype of the fields your are passing in payload, datatype of each field should match odata service, check metadata.

i doubt in MultipleMeterReadingReasonsFlag:"false", this might be boolean in the service.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Sep 04, 2017 at 10:39 AM
0

Hi,

I see you are using a localhost create an entry in the db.

in cases like this your request goes with a reference number or a callback function and this needs to be passed back from the request receiver for the ui to parse it.

for example if the request url is like this http:abcd.com/createSet?callback=1234;

then the response to be sent should be like "1234(<DATA>) "

and example of doing this in node is as follows: where my req.url contains the requesting url. and res.end is sent back with callbackfunction

http.createServer(function(req, res) {
	console.log('request url:' + req.url);
	res.writeHead(200,{'Content-Type':'application/json'});
	if(req.url === '/$metadata'){
		res.end('this is metadata');
	}else{
		var urlCb = req.url.split("?callback=")[1].split("&_=")[0];
		var obj = {
results:[
{
	name:'A',
	age:'22'
},
{
	name:'B',
	age:'22'
},
{
	name:'C',
	age:'22'
}
]
		}


		res.end(urlCb+"("+JSON.stringify(obj)+")");
	}

regards

GB

Share
10 |10000 characters needed characters left characters exceeded