on 07-25-2013 1:18 PM
Hi there,
I am trying to update data using the update method of a Netweaver Gateway (OData) Service from SAPUI5 or the Gateway Client (that shouldn't matter).
So far I can only get a valid HTTP Response if I am using XML as the request body data.
Is it possible to use an HTTP request with a request body data using a JSON string instead of the XML string? If this can be done, what do I have to do before using the 'update()' method of an ODataModel object.
Best Regards
Patrick
H Patrick,
Yes json payload is possible.
Check this link for more on json payload. http://www.odata.org/documentation/odata-v2-documentation/json-format/
You also need to give the below request header to tell the server that payload is json.
Content-Type: application/json
Thanks
Krishna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
{
"rowID": "50001444",
"cellValue": "true",
"columnID": "50002026"
}
Or is there a way to use JSON within the Gateway Client to test it without the use of JavaScript?
Best Regards and thanks in advance
Patrick
Hi Patrick,
First call your get service using $format=json then apply the below headers with the url and request body.
Use Headers:
1. x-csrf-token
2. Accept:application/json
3. Content-Type:application/json
Request Body:
{
"rowID": "50001444",
"cellValue": "true",
"columnID": "50002026"
}
Thanks,
Arun Chembra
You can also use Chrome Advanced Rest Client which is easy to use.
chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo/RestClient.html
Just use the key-value pairs and give content type as application/json.
Hi,
I am trying to use oData Update functionality. I have followed the steps mentioned in the thread to create the request. I am using below code to initialize the oDataModel.
var saveModel = new sap.ui.model.odata.ODataModel("http://ec2-54-213-97-224.us-west-2.compute.amazonaws.com:8000/workshop/sessiona/01/services/MarketIn...", true,null,null,{"Content-Type": "application/json;charset=utf-8"});
var oTable = sap.ui.getCore().byId('tableid');
var oModel = oTable.getModel();
var ModelData = oModel.getData();
for(var i = 0 ; i < 1 ; i++)
{
var id = ModelData[i].id;
var oEntry = {
"FRACTION":"4.3",
"MARKETID" : "00001",
"YEAR":"2013",
"MONTH":"08",
"INDUSTRY":"ENTERTAINMENT"
};
var oParams = {};
oParams.fnSuccess = function (){};
oParams.fnError = function () {};
saveModel.update("/MarketInfo('"+id+"')", oEntry, oParams);
}
I have set the bJSON flag to true and also set the Content -Type. However when I run the application I get 415 Unsupported Media Type Error.
Below is the trace:
The content type for request header is only application / json and this seems to be creating the problem. Please let me know how I can override the content type.
Thanks,
Aamod
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So, now it is working. the only things I changed from xml to JSON was:
Best Regards and thanks again
Patrick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
9 | |
8 | |
7 | |
6 | |
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.