on 12-02-2013 7:38 PM
Hi expert,
I implemented deep entity and it works for XML format.
I want to test it with JSON format.
Could you please help me to change this format to JSON as my HTTP Request input ?
and also please let me know what should i use in the Header for JSON ?
Header :
* X-CSRF-Token
* Content-Type : application/atom+xml
HTTP Request in XML
<?xml version="1.0" encoding="utf-8"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<atom:content type="application/xml">
<m:properties>
<d:DealerID>ABC1234</d:DealerID>
<d:DealerName>Dealer Automotive</d:DealerName>
<d:Street>123 Main Street</d:Street>
<d:City>Southfield</d:City>
<d:State>MI</d:State>
<d:PostalCode>40834</d:PostalCode>
</m:properties>
</atom:content>
<atom:link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/BankSet"
type="application/atom+xml;type=feed"
title="ZMASTERDATA_SRV.Bank">
<m:inline>
<atom:feed>
<atom:entry>
<atom:content type="application/xml">
<m:properties>
<d:BankAcct>1234567892</d:BankAcct>
<d:BankKey>122000247</d:BankKey>
<d:DealerID>ABC1234</d:DealerID>
<d:BankDetailID>TES8</d:BankDetailID>
</m:properties>
</atom:content>
</atom:entry>
</atom:feed>
</m:inline>
</atom:link>
</atom:entry>
Thank you in advance,
-Martin Darmawi-
Hi Martin,
I have not done this, but this is how I would approach.
In the GW Client, I would do a $expand with $format=json.
Then do a 'use as request'.
I believe the headers should be populated on its own.
Thanks
Krishna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Krishna,
it works with XML to 'use as request' - but it does NOT work for JSON for some reason.
This is the error message that I got
{
error:
code: "CX_SXML_PARSE_ERROR/001560AA0E081DEB8CA398CC1690D406"
message:
lang: "en"
value: "Error while parsing an XML stream"
}
-
innererror:
transactionid: "698E5BE3294BF1878C53842B2BFC45C1"
errordetails:
In this blog, author uses json data. UTF-8 might be required? But I do not think it should make any difference. Anyway check this out.
http://scn.sap.com/community/mobile/blog/2013/04/15/json-post-put-on-gateway
Hi Martin,
Thanks .......
Get Deep Entity : /sap/opu/odata/sap/ZMOB_AASTMGMT_SRV/NOTIFHEADER('000010000012')/?$expand=QMNUM
I am using the above URL for Get Deep Entity in Gateway Client,once i get the response i am using the same for create .
URL For Create Deep Entity :
http://XXXXXXXX:8000/sap/opu/odata/sap/ZMOB_AASTMGMT_SRV/NOTIFHEADER
Header: X-CSRF-==487fvi6p89p9-0unt8oh
Content-Type : application/json
Accept : application/json
{
"d":{
"__metadata":{
"uri":"http://XXXXXXXX:8000/sap/opu/odata/sap/ZMOB_AASTMGMT_SRV/NOTIFHEADER('10000012')","type":"ZMOB_AASTMGMT_SRV.NOTIFHEADER"},
"Breakdown":"X",
"Equipment":"10000002",
"LocAcc":"000000002216",
"Planplant":"1100",
"NotifNo":"10000012",
"NotifType":"ZB",
"ShortText":"Pump cavitating",
"Priotype":"PM",
"CreatedOn":"\/Date(1384992000000)\/",
"Notiftime":"PT14H57M11S",
"NotifDate":"\/Date(1384992000000)\/",
"PmWkctr":"10000178",
"Desstdate":"\/Date(1384992000000)\/","QMNUM":{
"results":[{
"__metadata":{
"uri":"http://XXXXXXXX:8000/sap/opu/odata/sap/ZMOB_AASTMGMT_SRV/NOTIFITEM(NotifNo='10000012',ItemKey='0001')","type":"ZMOB_AASTMGMT_SRV.NOTIFITEM"},
"NotifNo":"10000012",
"ItemKey":"0001",
"CreatedDate":"\/Date(1384992000000)\/",
"Prilang":"E",
"PosTime":"PT14H03M33S",
"ChangeTime":"PT00H00M00S",
"ItemSortNo":"0001"}]}}}
Thanks,
Arun
Hi Martin, Hi Arun,
The request body should not have below text for deep entity:-
{"results":
So, please remove text :-
{"results":
and corresponding closing bracket.
}
So Arun, after removing unwanted text, your request should be :-
{
"d":{
"__metadata":{
"uri":"http://XXXXXXXX:8000/sap/opu/odata/sap/ZMOB_AASTMGMT_SRV/NOTIFHEADER('10000012')","type":"ZMOB_AASTMGMT_SRV.NOTIFHEADER"},
"Breakdown":"X",
"Equipment":"10000002",
"LocAcc":"000000002216",
"Planplant":"1100",
"NotifNo":"10000012",
"NotifType":"ZB",
"ShortText":"Pump cavitating",
"Priotype":"PM",
"CreatedOn":"\/Date(1384992000000)\/",
"Notiftime":"PT14H57M11S",
"NotifDate":"\/Date(1384992000000)\/",
"PmWkctr":"10000178",
"Desstdate":"\/Date(1384992000000)\/","QMNUM":[{
"__metadata":{
"uri":"http://XXXXXXXX:8000/sap/opu/odata/sap/ZMOB_AASTMGMT_SRV/NOTIFITEM(NotifNo='10000012',ItemKey='0001')","type":"ZMOB_AASTMGMT_SRV.NOTIFITEM"},
"NotifNo":"10000012",
"ItemKey":"0001",
"CreatedDate":"\/Date(1384992000000)\/",
"Prilang":"E",
"PosTime":"PT14H03M33S",
"ChangeTime":"PT00H00M00S",
"ItemSortNo":"0001"}]}}
Please try it and let me know the results.
Regards,
Binson
hi Arun,
Will u share how u solve the issue, i am also following Binson format but still I am getting the error
"Error while parsing an XML stream" in response.I dont know where i am going wrong.
Here is My code
<script type="text/javascript">
var header_xcsrf_token;
OData.request
({
requestUri: "http://xxxxxxxxxxxx.com:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIHeaders",
method: "GET",
headers:
{
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"Accept": "application/atom+xml,application/atomsvc+xml,application/xml",
"DataServiceVersion": "2.0",
"X-CSRF-Token":"Fetch"
}
},
function (data, response)
{
header_xcsrf_token = response.headers['x-csrf-token'];
alert("xcrf"+ header_xcsrf_token);
//alert(data[0]);
}
);
function create()
{
var requestOptions = {
"d":{
"__metadata": {
"uri": "http://xxxxxxxxxxxx.com:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIHeaders(Plant='0100',SLOC='0100',Material='',PINo='0000000000',Fiscalyear='0000')",
"type": "ZPHYSICALINVENTORYCREATE.PIHeader"
},
"Plant": "0100",
"SLOC": "0100",
"Material": "",
"PINo": "0000000000",
"Fiscalyear": "0000",
"SpecialStock": "",
"DocumentDate": "\/Date(1385769600000)\/",
"PlannedDate": "\/Date(1385769600000)\/",
"PostingBlock": "",
"FreezeBookInv": "",
"DelBatches": "",
"PIRefNo": "",
"GroupingType": "",
"PINoLong": "",
"PIRefLong": "",
"PIItems":{
//[
"results":[
{
"__metadata": {
"uri": "http://xxxxxxxxxxxx.com:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIItems(Material='000000000000000230',PINo='',Fiscalyear='0000')",
"type": "PHYSICALINVENTORYCREATE.PIItem"
},
"BatchNumber": "0000000000",
"Material": "000000000000000230",
"PINo": "",
"Fiscalyear": "0000",
"StockType": "1",
"HandlingUOM": "X",
"SalesOrder": "",
"ItemNum": "000001",
"VendorAccNo": "",
"CustAccNo": "",
"WBSElement": "",
"LongMatnr": "",
"ExternalGUID": "",
"VerNo": "",
} ] },
}
};
//OData.request(requestOptions, AddSuccessCallback, AddErrorCallback);
OData.request({
requestUri: "http://xxxxxxxxxxxx.com:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIHeaders",
method: "POST",
data: requestOptions,
headers:
{
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/json;charset=UTF-8",
"DataServiceVersion": "2.0",
// "Accept": "application/atom+xml,application/atomsvc+xml,application/xml",
"Accept": "application/json",
"X-CSRF-Token":header_xcsrf_token
} ,
user:"xxxxxx",
password:"xxxxxx"
},AddSuccessCallback, AddErrorCallback,null);
}
function AddSuccessCallback(data, request)
{
alert("successfull" );
}
//AddUser Error Callback
function AddErrorCallback(error)
{
alert("error "+error.message);
}
</script>
Firstly through GET i am fetching ths XCSRF token then use this token while POST request,
Thanks in advance
Regards
Syed Shadan Quaiser
Hi Syed,
Please check the above post maybe its useful, you have to remove "result" for payload and also check for note if it is implemented in you ECC box.
"
We where able to resolve the issue after implementingNote # 1874920 and removing results tag
opening '{ "results" ' and corresponding closing '}'."
"
Regards,
Rajesh
HI Rajesh,
I have already removed the "result" part. but still its giving me same error.
just want to know that the SAP Note#1874920 is applicable only when POST in JSON format
or in POST through XML as well.
How to achieve the same in XML format.
Anyone Who has done please Guide.
Regards
Syed Shadan Quaiser
Hi Krishna,
will u please help in achieving deep insert in json format.
below i have pasted the code..
Here is My code
<script type="text/javascript">
var header_xcsrf_token;
OData.request
({
requestUri: "http://xxxxxxxxxxxx.com:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIHeaders",
method: "GET",
headers:
{
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"Accept": "application/atom+xml,application/atomsvc+xml,application/xml",
"DataServiceVersion": "2.0",
"X-CSRF-Token":"Fetch"
}
},
function (data, response)
{
header_xcsrf_token = response.headers['x-csrf-token'];
alert("xcrf"+ header_xcsrf_token);
//alert(data[0]);
}
);
function create()
{
var requestOptions = {
"d":{
"__metadata": {
"uri": "http://xxxxxxxxxxxx.com:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIHeaders(Plant='0100',SLOC='0100',Material='',PINo='0000000000',Fiscalyear='0000')",
"type": "ZPHYSICALINVENTORYCREATE.PIHeader"
},
"Plant": "0100",
"SLOC": "0100",
"Material": "",
"PINo": "0000000000",
"Fiscalyear": "0000",
"SpecialStock": "",
"DocumentDate": "\/Date(1385769600000)\/",
"PlannedDate": "\/Date(1385769600000)\/",
"PostingBlock": "",
"FreezeBookInv": "",
"DelBatches": "",
"PIRefNo": "",
"GroupingType": "",
"PINoLong": "",
"PIRefLong": "",
"PIItems":{
//[
"results":[
{
"__metadata": {
"uri": "http://xxxxxxxxxxxx.com:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIItems(Material='000000000000000230',PINo='',Fiscalyear='0000')",
"type": "PHYSICALINVENTORYCREATE.PIItem"
},
"BatchNumber": "0000000000",
"Material": "000000000000000230",
"PINo": "",
"Fiscalyear": "0000",
"StockType": "1",
"HandlingUOM": "X",
"SalesOrder": "",
"ItemNum": "000001",
"VendorAccNo": "",
"CustAccNo": "",
"WBSElement": "",
"LongMatnr": "",
"ExternalGUID": "",
"VerNo": "",
} ] },
}
};
//OData.request(requestOptions, AddSuccessCallback, AddErrorCallback);
OData.request({
requestUri: "http://xxxxxxxxxxxx.com:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIHeaders",
method: "POST",
data: requestOptions,
headers:
{
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/json;charset=UTF-8",
"DataServiceVersion": "2.0",
// "Accept": "application/atom+xml,application/atomsvc+xml,application/xml",
"Accept": "application/json",
"X-CSRF-Token":header_xcsrf_token
} ,
user:"xxxxxx",
password:"xxxxxx"
},AddSuccessCallback, AddErrorCallback,null);
}
function AddSuccessCallback(data, request)
{
alert("successfull" );
}
//AddUser Error Callback
function AddErrorCallback(error)
{
alert("error "+error.message);
}
</script>
Help me with this code
Thanks and regard
Syed shadan quaiser
Hi Arun,
I am facing a similar issue. i have implemented all the steps mentioned here. still i am getting the
"XML PARSING ERROR",Here is my code..
can u notice any error in this,then please let me know.
<script type="text/javascript">
var header_xcsrf_token;
OData.request
({
requestUri: "http://xxxxxxxxxx:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIHeaders",
method: "GET",
headers:
{
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"Accept": "application/atom+xml,application/atomsvc+xml,application/xml",
"DataServiceVersion": "2.0",
"X-CSRF-Token":"Fetch"
}
},
function (data, response)
{
header_xcsrf_token = response.headers['x-csrf-token'];
alert("xcrf"+ header_xcsrf_token);
//alert(data[0]);
}
);
function create()
{
var requestOptions = {
"d":
//{
{
"__metadata": {
"uri": "http://xxxxxxxxxx:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIHeaders(Plant='0100',SLOC='0100',...')",
"type": "ZPHYSICALINVENTORYCREATE.PIHeader"
},
"Plant": "0100",
"SLOC": "0100",
"Material": "",
"PINo": "0000000000",
"Fiscalyear": "0000",
"SpecialStock": "",
"DocumentDate": "\/Date(1385769600000)\/",
"PlannedDate": "\/Date(1385769600000)\/",
"PostingBlock": "",
"FreezeBookInv": "",
"DelBatches": "",
"PIRefNo": "",
"GroupingType": "",
"PINoLong": "",
"PIRefLong": "",
"PIItems":
// {
[
//"results":[
{
"__metadata": {
"uri": "http://xxxxxxxxxx:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIItems(Material='00000000000000023...')",
"type": "PHYSICALINVENTORYCREATE.PIItem"
},
"BatchNumber": "0000000000",
"Material": "000000000000000230",
"PINo": "",
"Fiscalyear": "0000",
"StockType": "1",
"HandlingUOM": "X",
"SalesOrder": "",
"ItemNum": "000001",
"VendorAccNo": "",
"CustAccNo": "",
"WBSElement": "",
"LongMatnr": "",
"ExternalGUID": "",
"VerNo": ""
//end of first object
}
//result ]
//end of array
]
// },
//end of d
}
//}
};
//OData.request(requestOptions, AddSuccessCallback, AddErrorCallback);
OData.request({
//requestUri: "http://xxxxxxxxxx:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIHeaders",
requestUri:"http://xxxxxxxxxx:8000/sap/opu/odata/sap/PHYSICALINVENTORYCREATE/PIHeaders",
method: "POST",
data: requestOptions,
headers:
{
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/json;charset=UTF-8",
// "Content-Type":"charset=UTF-8"
// "Content-Type":"multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b",
"DataServiceVersion": "2.0",
// "Accept": "application/atom+xml,application/atomsvc+xml,application/xml",
"Accept": "application/json",
"X-CSRF-Token":header_xcsrf_token
} ,
user:"xxxxxz",
password:"xxxxxxx"
},AddSuccessCallback, AddErrorCallback,null);
}
function AddSuccessCallback(data, request)
{
alert("successfull" );
}
//AddUser Error Callback
function AddErrorCallback(error)
{
alert("error "+error.message);
}
</script>
We are already on higher version.hence the SAP NOTE is not applicable.
Regards
Syed Shadan Quaiser
Hi Syed,
Sorry for the delay..... please find the below request body its working for me.
The issue which i faced because of
{"results":
and corresponding closing bracket.
}
URL : http://XXXXXXXX:8000/sap/opu/odata/sap/opu/odata/sap/ZMOB_AASTMGMT_SRV/NOTIFHEADER
Header: X-CSRF-==487fvi6p89p9-0unt8oh
Content-Type : application/json
Accept : application/json
Request Body:
{
"d":{
"__metadata":{
"uri":"http://XXXXXXXX:8000/sap/opu/odata/sap/ZMOB_AASTMGMT_SRV/
NOTIFHEADER('10000012')","type":"ZMOB_AASTMGMT_SRV.NOTIFHEADER"},
"NotifLongtext": " Test ",
"Maintloc": "100",
"NotifNo": "10000012",
"Maintplant": "1100",
"Planplant": "1100",
"LocAcc": "000000002216",
"AddrNumber": "22874","QMNUM":
[{
"__metadata":{
"uri":"http://XXXXXXXX:8000/sap/opu/odata/sap/ZMOB_AASTMGMT_SRV/
NOTIFITEM(NotifNo='10000012',ItemKey='0001')","type":"ZMOB_AASTMGMT_SRV.NOTIFITEM"},
"NotifNo":"10000012",
"ItemKey":"0001",
"CreatedDate":"\/Date(1384992000000)\/",
"Prilang":"E",
"PosTime":"PT14H03M33S",
"ChangeTime":"PT00H00M00S",
"ItemSortNo":"0001"}]}}
Thanks,
Arun
check this SAP Note:
http://service.sap.com/sap/support/notes/1922411
Build your JSON File from your GET Request and remove the "result" Tag as mentioned in this thread.
Let me Summarize checklist for Deep Insert with JSON. Hope it helps anyone coming here looking for a solution.
1. Implement Note 1874920
2. Ensure header Content-Type: application/json
3. In the request body, remove "results", "d" nodes
4. In any json string, last json property/value set should not have a 'comma' at the end
5. If a navigation property points to a multiple cardinality entity, then corresponding json value should be an array, even if it has single value/entry. ([ ]).
If a navigation property points to single cardinality entity, then corresponding json value should not be an array. ({ })
Hi Arun,
I am facing issue with json input body for deep_entity post method.
Please correct my coding is correct or not.
{
"SO_ID": "0",
"CURRENCY": "EUR",
"DOC_TYPE": "TA",
"DOC_DATE": "2015-07-27T00:00:00",
"SALES_ORG": "1000",
"DIST_CHANNEL": "10",
"DIVISION": "00",
"SALES_GRP": "130",
"SALES_OFF": "1030",
"REQ_DATE_H": null,
"PURCH_DATE": null,
"INCOTERMS1": "CIP",
"INCOTERMS2": "Nürnberg",
"PMNTTRMS": "ZB01",
"PRICE_DATE": "2015-07-27T00:00:00",
"PURCH_NO_C": "TEST ORDER",
"SO_ITEMSet":[{
"SO_ID": "0",
"ITEM_NO": "000010",
"MAT_NO": "100-100",
"PLANT": "1000",
"TARGET_QTY": "4",
"TARGET_QU": "ST",
"ITEM_CATEG": "TAN",
"PURCH_NO_C": "TEST ORDER",
"PURCH_DATE": "2015-07-27T00:00:00",
"INCOTERMS1": "CIP",
"INCOTERMS2": "Nürnberg",
"PMNTTRMS": "ZB01",
"PRICE_DATE": "2015-07-27T00:00:00",
"SALES_UNIT": "ST",
"DIVISION": "00",
"CURRENCY": "EUR"
}]
}
From the above header details working fine. but item details are empty in the structure.
Please help me.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.