Search code examples
javascriptinsomnia

How to extract part of header location url as variable in insomnia


I need to extract part of header location url (ticket number) to use on another request in insomnia, but I have no idea how to get that.

What I did so far was:

  1. First Request: https://domain-1.com Response Header Location: https://domain-2.com/tickets/ABC-1234

  2. Created a tag for the second request - https://domain-1.com/{response-header}

Function to perform:  Response
Attribute - Header
Request - (the other url)
Header name - Location
Trigger behaviour - when expired
Max age - 60s

Live preview: https://domain-2.com/tickets/ABC-1234

But on the query url, i'm getting: https://domain-1.com/https://domain-2.com/tickets/ABC-1234

And I expect: https://domain-1.com/ABC-1234

Can someone give me a light?


Solution

  • Just found the solution.

    Create a folder, put the both requests on it and edit folder environment with the information below:

    {
        "location": "{{% response 'header', 'req_xxxxxxxxxx', 'b64::TG9xxxx', 'when-expired', 60 %}}",
        "code": "{{ location | replace('https://domain-2.com/tickets/', '')}}"
    }
    

    Then use the tag "code" on request:

    https://domain-1.com/{{code}}