cancel
Showing results for 
Search instead for 
Did you mean: 

Posting data in Json format in OData services

Former Member
0 Kudos

Hi All,

I am aware with SAP Gateway service we can send and receive data in XML format.. Just curious to know if we can receive request with data in Json format and process it in ECC...

Our front end application is using Json format and we are checking if can process request in same format in ECC or we need to transform it to XML before sending request to ECC. .

Please advice

Regards,

Rajesh

Accepted Solutions (1)

Accepted Solutions (1)

kammaje_cis
Active Contributor
0 Kudos

Rajesh,

json is very much supported for request body as well. Check this.

http://scn.sap.com/community/mobile/blog/2013/04/15/json-post-put-on-gateway

Note the Content-Type header.

Regards

Krishna

Former Member
0 Kudos

Thanks Krishna, I will check for given info and update the thread..

Former Member
0 Kudos

Hi Krishna,

I followed the document but I am getting following error:

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

- <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

<code>CX_SXML_PARSE_ERROR/001560AA0E081DEB8CA398CC1690D406</code>

<message xml:lang="en">Error while parsing an XML stream</message>

- <innererror>

<transactionid>52C6690B976D27EDE100000014949326</transactionid>

<errordetails />

</innererror>

</error>


    In request header i have set Content-Type = application/json; charset=utf-8.. Any suggestions to follow..


    Thanks







binson
Advisor
Advisor
0 Kudos

Hi Rajesh,

Could you please try the same operation from Gateway client (TCode: /iwfnd/gw_client) or from any rest client and attach the screenshot of the same?

Please attach the screenshot of /iwfnd/error_log entry also.

Regards,

Binson

Former Member
0 Kudos

Hi,

I am using Gateway client (TCode: /iwfnd/gw_client) and I have pasted error which I am getting in above post..Seems like its not reading Json format and expecting it in XML format..

Regards,

Rajesh

binson
Advisor
Advisor
0 Kudos

hi Rajesh,

Please give a screenshot of Gateway client, with request and response (along with header values).

Regards,

Binson

kammaje_cis
Active Contributor
0 Kudos

The header name is case sensitive in SAP. (even though w3.org says otherwise).

Hope you have got it right. It has to be "Content-Type: application/json"

Former Member
0 Kudos

Hi Binson,

We are trying to get request in Json format with multiple line items using deep entity method.. its working for XML...

URI for GET Request:

/sap/opu/odata/sap/ZPA_TIMESHEET_SRV/Emp_Headers(Pernr='00000016',Fromdate=datetime'2013-01-01T00%3A00%3A00',Todate=datetime'2013-12-29T00%3A00%3A00',Profile='Z_TE01')?$expand=Emp_Times&$format=json

and we are using response body as request by clicking button "Use as Request"

Following is the screen shot after trying to post the request:

Please advice..

Thanks

kammaje_cis
Active Contributor
0 Kudos

This has to fix it.

1751991 - OData Channel - Deep Insert in JSON Format Leads to Error

Former Member
0 Kudos

Thanks Krishna, We have this note implemented.. and all the correction already in place..

former_member184867
Active Contributor
0 Kudos

Hi Rajesh,

Deep insert with empty field in JSON payload leads to parsing error. Checkout note 1874920

Regards,

Atanu

binson
Advisor
Advisor
0 Kudos

Hi Rajesh,

Your request JSON body text is NOT correct. The request body should not have below text for deep entity:-

{"results":

So, please remove text :-

{"results":

and corresponding closing bracket.

}

Please check below link for more details :-

http://scn.sap.com/message/14659195#14659195

Regards,

Binson

Former Member
0 Kudos

Hi Binson,

I have done as you suggested.. any how its still not working and giving same error.. I am sharing the payload with you.. If you can point out and correct. I have added my comments on rows which I have removed..

{

  "d" : {

    "__metadata" : {

      "id" : "http://<**********>/sap/opu/odata/sap/ZPA_TIMESHEET_T_SRV/Emp_Headers(Pernr='00000016',Fromdate=datetime'2013-12-24T00%3A00%3A00',Todate=datetime'2013-12-29T00%3A00%3A00',Profile='Z_TE01')",

      "uri" : "http://<**********>/sap/opu/odata/sap/ZPA_TIMESHEET_T_SRV/Emp_Headers(Pernr='00000016',Fromdate=datetime'2013-12-24T00%3A00%3A00',Todate=datetime'2013-12-29T00%3A00%3A00',Profile='Z_TE01')",

      "type" : "ZPA_TIMESHEET_T_SRV.Emp_Header",

      "properties" : {

        "Emp_Times" : {

          "associationuri" : "http://<**********>/sap/opu/odata/sap/ZPA_TIMESHEET_T_SRV/Emp_Headers(Pernr='00000016',Fromdate=datetime'2013-12-24T00%3A00%3A00',Todate=datetime'2013-12-29T00%3A00%3A00',Profile='Z_TE01')/$links/Emp_Times"

        }

      }

    },

    "Pernr" : "00000016",

    "Fromdate" : "\/Date(1387843200000)\/",

    "Todate" : "\/Date(1388275200000)\/",

    "Profile" : "Z_TE01",

    "Emp_Times" :

**** Here I have removed the result     { "results" :

  [

        {

          "__metadata" : {

            "id" : "http://<**********>/sap/opu/odata/sap/ZPA_TIMESHEET_T_SRV/Emp_Times(Counter='000000000588',Pernr='00000016',Profile='Z_TE01',Todate=datetime'2013-12-29T00%3A00%3A00',Fromdate=datetime'2013-12-24T00%3A00%3A00')",

            "uri" : "http://<**********>/sap/opu/odata/sap/ZPA_TIMESHEET_T_SRV/Emp_Times(Counter='000000000588',Pernr='00000016',Profile='Z_TE01',Todate=datetime'2013-12-29T00%3A00%3A00',Fromdate=datetime'2013-12-24T00%3A00%3A00')",

            "type" : "ZPA_TIMESHEET_T_SRV.Emp_Time",

            "properties" : {

              "Emp_Headers" : {

                "associationuri" : "http://<**********>/sap/opu/odata/sap/ZPA_TIMESHEET_T_SRV/Emp_Times(Counter='000000000588',Pernr='00000016',Profile='Z_TE01',Todate=datetime'2013-12-29T00%3A00%3A00',Fromdate=datetime'2013-12-24T00%3A00%3A00')/$links/Emp_Headers"

              }

            }

          },

          "Counter" : "000000000588",

          "Lstar" : "H11",

          "Lstnr" : "",

          "Rkostl" : "",

          "Rproj" : "U-010000038.0010",

          "Approved" : "",

          "Awart" : "",

          "Lgart" : "",

          "Tasktype" : "",

          "Status" : "40",

          "Refcounter" : "",

          "Reason" : "",

          "Catshours" : "7.00",

          "Catsamount" : "0.00",

          "ZzworkLoc" : "WL01",

          "Zzcreason" : "",

          "ZzlabortypeDesc" : "",

          "Action" : "",

          "Pernr" : "00000016",

          "Workdate" : "\/Date(1388016000000)\/",

          "Skostl" : "C120699998",

          "ZzLabortype" : "",

          "ZzBillFlag" : "",

          "ZzTask" : "",

          "Profile" : "Z_TE01",

          "Todate" : "\/Date(1388275200000)\/",

          "Fromdate" : "\/Date(1387843200000)\/",

          "Emp_Headers" : {

            "__deferred" : {

              "uri" : "http://<**********>/sap/opu/odata/sap/ZPA_TIMESHEET_T_SRV/Emp_Times(Counter='000000000588',Pernr='00000016',Profile='Z_TE01',Todate=datetime'2013-12-29T00%3A00%3A00',Fromdate=datetime'2013-12-24T00%3A00%3A00')/Emp_Headers"

            }

          }

        }

      ]

    }

  }

}  **** Also remove this for corresponding "results"

Thanks

binson
Advisor
Advisor
0 Kudos

Hi Rajesh,

Would it be possible to create an OSS ticket and open service connection? We shall login to the system and check the issue.

Regards,

Binson

Former Member
0 Kudos

Hi,

We where able to resolve the issue after implementing Note # 1874920 and removing results tag

opening '{   "results" ' and corresponding closing '}'.

Thanks for useful inputs..

Regards,

Rajesh

Former Member
0 Kudos

Hello Rajesh,

Can you please post the Create JSON format that you have coded in the GWclient please.

I am creating deep entity create option. i want the correct JSON format for POST operation.

Thanks in advance.

former_member184867
Active Contributor
0 Kudos

You can create a POST JSON payload for yourself.  If you run a read entity in GW_CLIENT with /sap/opu/odata/.../myservice/MyEntitySet(key)?$format=json, you will get the response in JSON.

Now if you click on the 'Use as Request' , you can get the request body for a POST on the left hand side of the GW_CLIENT

Former Member
0 Kudos

Hi Nitin,

As Atuna said you can create the request body for POST by using the response body.. Only thing you need to do is to remove opening '{   "results" ' and corresponding closing '}'.

Regards,

Rajesh

Answers (0)