Skip to Content
avatar image
Former Member

How to extract crsf token from REST API response header.

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)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Feb 28 at 03:44 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

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

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 24 at 12:19 PM

    Hi Nida,

    Have you achieved this requirement?

    Thanks ,

    Raghava.

    Add comment
    10|10000 characters needed characters exceeded

  • May 28 at 07:38 AM

    Hi Nida ,

    Do you find any solution for this requirement?

    Best ,Shiva

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 02 at 01:22 PM

    Dear Team,

    we got one business requirement where we need to call the JSON API in our ESS portal.

    we need to call the API using the authorization token generated run time dynamically.

    based one first token get the second token as response.

    then based on the second token call the below API in ESS portal.

    ADD API https://apigee.net/v1/members

    Update a member API end point in QA: https://apigee.net/v1/members/{memberId}

    i am new to This topic.

    so kindly can u help me asap with the complete solution step by step.

    Regards,

    Manjunath

    Add comment
    10|10000 characters needed characters exceeded