3

If this is the raw data I can see in an API response from a simple GET request made on Insomnia to a website:

   <!DOCTYPE html>
      <head>
        <meta charset="utf-8" />
        <meta content="authenticity_token" name="csrf-param" />
    <meta content="abcdefg=" name="csrf-token" />
      </head>

      <body></body>
    </html>

How would I access the csrf-token value of abcdefg using XPATH if I am wanting to chain the response above such that I can use the csrf token in the headers another Insomnia request?

This is what is what I thought was correct: head/meta[@name='csrf-param']

If I only include head/meta the live preview is Returned more than one result: head/meta.

In the image below, you can see how this is set up but it appears that there is an "error" in the live response.

Image of the error I see when I try to filter the response body

matt-d
  • 71
  • 5

2 Answers2

3

This will get the value of abcdefg from csrf-token:

//head/meta[@name='csrf-token']/@content
Peter
  • 848
  • 8
  • 14
0

In my case there were two instances of the respective element, e.g.

   <!DOCTYPE html>
      <head>
        <meta charset="utf-8" />
        <meta content="authenticity_token" name="csrf-param" />
        <meta content="abcdefg=" name="csrf-token" />
        <meta content="abcdefg=" name="csrf-token" />
      </head>

      <body></body>
    </html>

which is why I needed

(//meta[@name='csrf-token'])[1]/@content

I know this doesn't answer the exact question but it extends the accepted answer and might help other people coming here.

MoRe
  • 1,478
  • 13
  • 25