cancel
Showing results for 
Search instead for 
Did you mean: 

CPI : Accessing Response Header

prabhu_s2
Active Contributor
0 Kudos
5,134

Hi

I'm calling an API which returns the payload and the message headers. Testing in POSTMAN i can view the response headers but when implementing with Request-Reply I do not see those response headers [in trace].

API documentation for response headers:

1. Not sure if this is a common behavior and why those headers are not returned [without groovy]?

2. So, i used the below groovy to read the header response but the property is returned as null.

def Message processData(Message message){
      
     def headers = message.getHeaders();
     def gSr_token = headers.get("elements-next-page-token");


     message.setHeader("gProp_token", gSr_token);
     
      return message;
}

Any thoughts and advise on this please?

Accepted Solutions (0)

Answers (8)

Answers (8)

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Prabhu,

Thanks for the update it really helps our fellow community members.Please close the thread marking helpful answer ( if any ).

Regards,

Sriprasad Shivaram Bhat

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Prabhu,

I think there is a threshold for header size and rest of the headers might be getting truncated because of this.Since I dont have ServiceNow account to test this Connector its very difficult to replicate your scenario ( since for rest of the elements I am getting response headers as expected ).Suggest you to raise a ticket to LOD-HCI-PI-CON with all the findings and somebody from developement team will look into it.

Regards,

Sriprasad Shivaram Bhat

prabhu_s2
Active Contributor
0 Kudos

Thank you. Just had a response from SAP saying the custom headers are not yet supported and in the backlog for future release.

prabhu_s2
Active Contributor
0 Kudos

Enabling page settings :

will provide the following:

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Prabhu,

Could you please try below.

Regards,

Sriprasad Shivaram Bhat

prabhu_s2
Active Contributor
0 Kudos

Hi

Ye, that had been tried and didnt get the custom headers

rivasch
Explorer
0 Kudos

Hi c12b61ded10b4e18beae75c3b6218d2c,

All you need is to register the custom headers, in the iflow runtime configuration section.

And you can use the groovy code.

def Message processData(Message message){
      
     def headers = message.getHeaders();
     def gSr_token = headers.get("elements-next-page-token");


     message.setHeader("gProp_token", gSr_token);
     message.setProperty("gProp_token", gSr_token);
     
      return message;
}

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Morten,

I think he is using http or open connectors adapter. From response it looks to me like open connectors response header for service now instance.

But let Prabhu confirm based on that we can derive some solution.

Regards,

Sriprasad shivaram Bhat

MortenWittrock
SAP Mentor
SAP Mentor
0 Kudos

Yeah, let's see. Definitely for HTTP, all response headers should be available after Request Reply.

Regards,

Morten

prabhu_s2
Active Contributor
0 Kudos

hi,

yes it is open connectors and not http. when i enable the pagination options in the open connector adapter i couple of the customr headers [the much needed ones] but it is prefixed with 'SAP_' and suffixed with other characters which i can work it out in groovy

saranya_baskaran2
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Prabhu,

OData Receiver adapter do not copy all the response headers back to message.

You have to whitelist the Response headers that you wish to copy. Please refer https://blogs.sap.com/2019/01/16/sap-cloud-platform-integration-headers-whitelisting-in-odata-v2-out...

BR
Saranya

MortenWittrock
SAP Mentor
SAP Mentor
0 Kudos

Ah, hang on - I assumed an HTTP adapter. You are probably correct that this is the issue, then 🙂

Regards,

Morten

prabhu_s2
Active Contributor
0 Kudos

I'm using open connectors. With HTTP , yes i do see all headers as used in other implementation but for the current one i dont use http.

FYI - the custom header is been pushedback from open connectors but only when the pagination options are enabled in the adapter.

MortenWittrock
SAP Mentor
SAP Mentor
0 Kudos

Hi Prabhu

Are the other documented headers present after the Request Reply step? I can't really see that you are doing anything wrong, and that makes me wonder whether the header is present at all.

Are you passing query parameters that are similar to the ones you pass in Postman?

Regards,

Morten

prabhu_s2
Active Contributor
0 Kudos

Hi Morten

the query parameter "nextPage" is optional. Testing without "nextPage" or any of the request headers in postman still provides the response header(s) "elements-next-page-token" [these are custom header]

Not sure, if i had misunderstood your question, do i need to request for "elements-next-page-token" prior request-reply step via content modifier? I dont have this content modifier prior the request-reply

MortenWittrock
SAP Mentor
SAP Mentor
0 Kudos

Hi prabhu.s2

The request returns quite a few other headers in Postman. Do you see those headers in CPI?

Regards,

Morten

prabhu_s2
Active Contributor
0 Kudos

hi Morten,

Nope, i dont see those aswell. Postman return 15 response headers but none are seen in cpi