on 11-03-2014 2:24 PM
Hi All,
I am pretty new to Gateway Services. I am trying to create a record into SFLIGHT table through gateway services, for the same I have created an Entity and entitySet with table structure SFLIGHT. I am able to get the metadata for the service I have created.
When I am trying to create a new record through gateway client , with the following request URI with HTTP post method, I am getting error Invalid key predicate with HTTP status ~status_code 400.
/sap/opu/odata/sap/ZGW_XXXXXXXXXXX/ETY_ADD_FLIGHTSet(Carrid = 'AF' Connid = '0820' Fldate eq datetime'2014-03-11T13:01:02')
Method redefined in DPC_EXT class.
ETY_ADD_FLIGHTSE_CREATE_ENTITY
DATA: ls_flight TYPE SFLIGHT.
io_data_provider->read_entry_data( IMPORTING es_data = er_entity ).
MOVE-CORRESPONDING er_entity TO ls_flight.
INSERT SFLIGHT FROM ls_flight.
endmethod.
Request you all to help me in resolving whats the correction.
Regards,
Madhav
Hello Madhav,
Please correct ur URL.
To perform Create/POST operation the url shud be as below :
/sap/opu/odata/sap/ZGW_XXXXXXXXXXX/ETY_ADD_FLIGHTSet
The data which u would like to POST to backend shud go as part of payload in XML or JSON format.
JSON ->
{
"Carrid":"AF",
"Connid":"0820",
"Fldate":"2014-03-11T13:01:02"
}
Add Headers as below :
x-csrf-token : <fetched value> - - - U can use the metadata URL of ur POST service itself to fetch the the csrf token
Content-Type: application/json
Accept : application/json - - - to get response in JSON format
Set HTTP method to POST
Regards,
Ashwin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Madhav,
Invalid key predicate - refers the properties which you mentioned as a key in Entity are not been used in your Request URI.
x-csrf-token - which will fetch the csrf token using Get request from the SAP and sends the same while using PUT or POST operations for validation from the front end.you can refer link in my earlier post.
Regards,
Vijay V
Hello Madhav,
U get that error when u are not passing/ incorrectly passing a KEY property as per the URI convention which u would have defined as key in ur GW model.
Any Modifying request u fire ( Create / Update / Delete ), token to be passed.
I would suggest u to have a look at the below for details explanation related to CSRF Token.
Regards,
Ashwin
Hi Madhav,
Please follow the below link for all HTTP operations.
http://scn.sap.com/community/mobile/blog/2013/04/15/json-post-put-on-gateway
Regards,
Vijay V
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
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.