javascriptresponsepaw

paw: copy response field into environment


Using Paw, I am accessing an endpoint that I use to make an authentication request. The response is returned via JSON and contains a sessionId, which I need to place into my environment as a variable (SESSION_ID). This environment variable is then used in the Authorization header of all requests sent back to the server.

Is there a way to script the extraction of the sessionId value from the authentication response and place the value into the environment variable, without having to perform a copy and paste each time I authenticate?

Thank you for the assistance.


Solution

  • Sorry for the late answer. The right way of achieving this in Paw is in a declarative manner. Instead of extracting from the response on each call, you set the environment variable's value to point to a specific field within this JSON response.

    For that, the Response Parsed Body Dynamic Value will be helpful.

    1. On the JSON or Form URL-Encoded response, right click on a field and pick "Copy as Response Body Dynamic Value":

    Copy a Response Body Dynamic Value from a Response Field in Paw

    1. Paste it on your environments, or in any field you want:

    Use a response field anywhere in Paw

    You can read the documentation about this.