cancel
Showing results for 
Search instead for 
Did you mean: 

Calling an OData V4 custom action from within an iFlow.

Anthony_P
Discoverer
0 Kudos
219

Hi,

I've built a custom action in backend S4 using RAP. Its purpose is to sync a Z-table in S4 with data read from an on-prem SQL Server. It works perfectly from Postman when I call it via a POST to https://xxxHostnamexxxx:44300/sap/opu/odata4/sap/zui_i_cv_person_api_o4/srvd_a2x/sap/zui_i_cv_perso....

I've tried incorporating it into an iFlow using the OData adaptor. This works fine for standard operations, like say using GET to return the top 10 records for the people entity. This is with Address: http://xxxCloudConnectorVirtualhostxxxx:44300/sap/opu/odata4/sap/zui_i_cv_person_api_o4/srvd_a2x/sap... and Resource Path: people.

From my Postman trial I know the URL to the custom action ends in people/SAP__self.upsert_many. I tried using this as the Resource Path, but I get the error "com.sap.it.rt.adapter.http.api.exception. HttpResponseException: An internal server error occured: Resource path not found people/SAP__self.upsert_many". Is it possible to invoke a custom action using the OData adaptor?

I then tried using the HTTP adaptor to do a POST to the explicit URL, but I have to manage the CSRF protection manually and I can't work out how to pass the CSRF token to the POST operation after having called a GET to obtain the token. In this case I get this error {"error":{"code":"/IWBEP/CM_V4H_RUN/043","message":"CSRF token is missing","@SAP__common.ExceptionCategory":"CSRF_Token_Missing"}}

This is my first time using ABAP RAP and first time with SAP BTP. Maybe passing data en masse via a custom action isn't the right approach. Any help would be appreciated. 

- Anthony.

Accepted Solutions (1)

Accepted Solutions (1)

Anthony_P
Discoverer
0 Kudos

I've got calling the custom action to work using the HTTP adapter. This is what I did to get the CSRF working:

1) Do a HTTP GET on anything supported by the service. E.g. /$metadata. Need to pass X-CSRF-Token=Fetch in the request header

Anthony_P_1-1745975518141.png

Anthony_P_0-1745975435621.png

2) This prompts the backend system to generate a CSRF token and pass it back in the response header. I used this Groovy script to pull out the CSRF token and the session cookies and store them in properties. 

Anthony_P_2-1745975835159.png

3) Now pass both the X-CSRF-Token and Cookies to the POST operation. Tip: the cookies are passed back from the original GET in header field Set-Cookies. When passing them in the request header to the POST you need to use header field Cookies.

Anthony_P_3-1745976147869.png

Anthony_P_5-1745976389474.png

This is my first iFlow, so it's probably not an ideal solution, but it works. Hope this helps someone.

- Anthony.

 

 

Answers (0)