cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Getting 400 while calling S4hana service from SAP CPI

satheshM
Explorer
0 Likes
22,880

"I am trying to integrate an S/4HANA system service into my CPI. Basically, I need to use two APIs: one for getting a CSRF token and another for making a POST request. When calling the first API, I need to pass x-csrf-token: Fetch in the header with a GET request. This should return an x-csrf-token in the response, which I will then use to call the second POST API.

The issue I’m facing is that when I call the first API, I receive the same header I sent to the server, rather than the expected x-csrf-token. In Postman, it correctly returns the x-csrf-token, but when I implement it in my code, the response returns with the same header value I sent, i.e., x-csrf-token: Fetch. I'm not sure why this is happening, and when I call the second API, it also returns a response like.

 

Error Details
com.sap.it.rt.adapter.http.api.exception.HttpResponseException: An internal server error occured: Bad Request : 400 : HTTP/1.1 . The MPL ID for the failed message is : XXXXXXXXXXXX
 
  After I check the open TEXT view I can see the Request url Request URI         = GET https:XXXXXXXX/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder/$metadata HTTP/1.1
 
but the actull url is in  postman I am useing post Url as https:XXXXXXXX/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder 
 
so I think it happen because of oData Adapter 
satheshM_0-1722496501979.png

 

satheshM_1-1722496739413.png

oData1 config :

satheshM_2-1722496815669.pngsatheshM_3-1722496861354.pngsatheshM_4-1722496956457.png

this adapter return 200 ok there is no big problem also it have minor problem It response header is x-csrf-token : Fetch  but it should be some token value .

 

and oData adapter 2 config:

 

satheshM_5-1722497101872.pngsatheshM_6-1722497139601.pngsatheshM_7-1722497182053.png

 

satheshM_9-1722497389845.png

 

P;ease anyone help me what I did wrong in these steps , Also the same url working in post man 

 csrf-token url

satheshM_8-1722497362195.png
 
 
Post url
satheshM_10-1722497549455.png

 

Plz anyone help me to find out the reason Thanks in adavance 

 

@SAPSupport  @Sisn  @SAPSUPPORT2  @DonWilliams  @N1kh1l   @Dan_Wroblewski @Ryan-Crosby  @Sandra_Rossi 

 

Accepted Solutions (0)

Answers (1)

Answers (1)

Ryan-Crosby
Active Contributor
0 Likes

It's because the URL for the fetch of the metadata by the OData adapter is incorrect on account of the addition of the entity A_SalesOrder.  The URL is showing as "https:XXXXXXXX/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder/$metadata" but should be "https:XXXXXXXX/sap/opu/odata/sap/API_SALES_ORDER_SRV/$metadata".

 

Regards,

Ryan Crosby

satheshM
Explorer
0 Likes
"The Request URI is currently set to a GET method (https://XXXXXXXX/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder/$metadata), but it should be configured as a POST method with a JSON request payload according to the configuration. Essentially, I need to use the OData adapter to make a POST request to call the S/4HANA service."
Ryan-Crosby
Active Contributor
0 Likes
@satheshM using the OData adapter means it is going to execute a metadata request before the OData request that you intend... it does this by design.