Skip to content

Set token from API Response #3465

Answered by morkotns
morkotns asked this question in Q&A
Discussion options

You must be logged in to vote

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);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by morkotns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant