-
Hi I am new to Bruno and an amateur REST coder. I successfully send a login request for a token and receive the following Response: I need to extract and assign the token to a variable. This would normally done with the JS request: /DM2ContentIndexing_CheckCredentialResp/@token This format does not work with bro.setEnvVar and I am not sure how to go about extracting the path from the response. Any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I used a post response script with regex to capture the information required: // Assuming responseBody contains the XML response text // Use a regular expression to match and extract the token attribute // Set the extracted token value as a variable in Bruno |
Beta Was this translation helpful? Give feedback.
I used a post response script with regex to capture the information required:
// Assuming responseBody contains the XML response text
let responseBody = res.body;
// Use a regular expression to match and extract the token attribute
const tokenMatch = responseBody.match(/token="([^"]+)"/);
const tokenValue = tokenMatch ? tokenMatch[1].trim() : null;
// Set the extracted token value as a variable in Bruno
bru.setEnvVar("cvToken", tokenValue);