cancel
Showing results for 
Search instead for 
Did you mean: 

How to use json to create in odata?

0 Kudos

hi,

i have field  id,name,address.

how to create above records using json in htpp request side?

My entity set name is sample_odataset

thanks.

Accepted Solutions (0)

Answers (2)

Answers (2)

scott_stefanich
Active Participant
0 Kudos

Hello Narendra,

Using the SAP NetWeaver Gateway Client,

1. Perform an HTTP GET with the following Request URI to get the service metadata:

/sap/opu/odata/sap/Z..SRV/$metadata

2. Confirm an EntitySet with the name "sample_odataset" exists, then perform an HTTP GET to get the set:

/sap/opu/odata/sap/Z..SRV/sample_odataset



3. Perform an HTTP GET for a specific entity in the set with a JSON format parameter. For example, an entity with a key value of '1' would have a Request URI as follows:


/sap/opu/odata/sap/Z..SRV/sample_odataset('1')?$format=json



4. The entity should be returned as JSON in the HTTP Response section. To use the resulting JSON for a create (HTTP PUT),


- Press the button 'Use as Request'. The X-CSRF-Token is added to the HTTP Request Header.

- Change the URI from the entity to the entity set: /sap/opu/odata/sap/Z..SRV/sample_odataset

- Select HTTP Method PUT

- Modify the HTTP Request JSON, for example, changing the key property's value.

- Execute and see what happens

I suggest starting from the above and we can go from there, e.g. if you are ultimately trying to create a record from a SAPUI5 app.

Regards,

Scott


AshwinDutt
Active Contributor
0 Kudos

Hello Hedge,

There are already explained steps in the forum. You may search.

However Fire as below :

I assume id, name and address are the properties defined in your GW Model.

URL ->

/sap/opu/odata/sap/ZODATA_SERVICE_SRV/sample_odataset

HTTP Method ->

POST

Headers to be set/passed ->

Content-Type : application/json

Accept : application/json

Json Payload ->

{

"id":"101",

"name":"Nick",

"address":"London"

}

Regards,

Ashwin

rakshit_doshi
Active Contributor
0 Kudos

You would also need an X-CSRF-Token if you are doing and testing from outside the SAP GUI. It can be  acquired by doing a GET request on the same service and setting the header as

X-CSRF-Token with value fetch

Supply this with the body as mentioned by Ashwin and you should be able to create data using JSON.

Hope this helps,

Thanks,

Rakshit Doshi