Skip to Content
0

How to extract crsf token from REST API response header.

Feb 28 at 02:43 PM

164

avatar image
Former Member

Hi All,

I am working on REST API to PUSH data over it but we have condition here that for successful PUSH authentication we need to provide a x-csrf-token value as header value in our PUSH REST receiver channel as Header parameter.

So the approach will be we will have to first do the GET operation on same API, which will return the csrf token in Response Header as below:

Now my approach would be to write a REST LOOKUP UDF in PI mapping and extract the response header and pass it as value to one of the target field. If I will get success here then I will be able to pass it as custom header.

I need your help in writing Java code for REST LOOKUP to fetch the csrf token value.

Java expert please help.

Thanks,

Nida Fatima

getsreenshot.jpg (53.4 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Manoj K Feb 28 at 03:44 PM
1

Nida,

Recently i came across the same requirement this is how i did :

Create 2 interfaces:

1.Your actual sender with Receiver REST API(PUT) with dynamic http header enabled.

2.SOAP to REST API(GET) with a header as x-csrf-token as fetch , now once you have fetched read it via dynamic config and put it in some response payload.

Call the 2 interface via first interface mapping and read the response payload of x-csrf token and set to dynamic config , note along with x-csrf token i had to fetch and update cookie as well . This worked for me.

Will try to write a blog on this once i get some time.

Br,

Manoj

Show 5 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Manoj,

Thanks for your reply.

As far I understand, we will get the csrf token in Response Header of GET request.

Could you please help me with settings/code you have done for extracting the header content of the response given by GET REST receiver channel.

Quick help would be appreciated.

Regards,

Nida

0

Interesting.. calling pi interface instead of calling channel for look up.

1
Former Member

Hi Muni,

I read in the below blog that you were able to achieve it by some Dynamic Config.

https://archive.sap.com/discussions/thread/3798345#

Can you please let me know your channel settings for this ?

Thanks,

NIda

0

Not sure if you get the point.

As manoj said, the main interface will be with PUT operation and lookup call(Soap lookup).

In the second interface, SOAP to REST, you can read the header information in the response message mapping using dynamic configuration (using udf ) and map it to response output structure.

This second interface will be called via soap lookup from first interface.(Look up will have to point to sender soap channel)

I used different approach for my requirement pelase read below blog comments section https://blogs.sap.com/2015/09/11/yes-rest-lookup-is-possible-in-pi/

0
Former Member

Hi Mani,

My question is why do we need to do all this. As per SAP latest documentation SAP states that

"The HTTP headers of the HTTP result message are copied into the XI message as dynamic message attributes and are therefore available for later reference."

https://help.sap.com/viewer/5cf7d2de571a45cc81f91261668b7361/7.5.11/en-US/b4076c130bef4cd7b414d35a0f266fe5.html

We are on latest SP: 7.5 SP10

Need help of you guys I implementing the same.

Thanks,

nida

0
avatar image
Former Member Mar 05 at 10:36 AM
0

Hi Manoj,

Thanks for your reply.

As far I understand, we will get the csrf token in Response Header of GET request.

Could you please help me with settings/code you have done for extracting the header content of the response given by GET REST receiver channel.

Quick help would be appreciated.

Regards,

Nida

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Via Rest Lookup i don't see there is an option to read the token as this is part of header hence i setup a different interface to read that as mentioned above.

0
Former Member

Hi Manoj,

Please share how have you done your channel configuration to get the response header.

Thanks,

Nida

0

Hi Nida / Manoj ,

Do you get a solution for this requirement??

Best ,Shiva

0
Raghava B Apr 24 at 12:19 PM
0

Hi Nida,

Have you achieved this requirement?

Thanks ,

Raghava.

Share
10 |10000 characters needed characters left characters exceeded
G SHIVA May 28 at 07:38 AM
0

Hi Nida ,

Do you find any solution for this requirement?

Best ,Shiva

Share
10 |10000 characters needed characters left characters exceeded