cancel
Showing results for 
Search instead for 
Did you mean: 

Create Entity Set - Error

former_member227181
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

AshwinDutt
Active Contributor
0 Kudos

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

former_member227181
Participant
0 Kudos

Hi Ashwin,

It resolved my issue, can you please let me know Invalid key predicate does mean. Since I am a beginner in building GW Services, can you please let me know what does x-csrf-token mean ?


Regards,

Madhav

vijaybhaskarraju_vegesana
Active Participant
0 Kudos

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

AshwinDutt
Active Contributor
0 Kudos

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

Answers (2)

Answers (2)

vijaybhaskarraju_vegesana
Active Participant
0 Kudos

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

kammaje_cis
Active Contributor
0 Kudos

Madhav,

This blog by Chandra can help you.

Also go through the troubleshooting guide here.