Reputation: 1
{
"id": 115084015,
"from": "[email protected]",
"subject": "Verify Code",
"date": "2022-12-27 19:53:45",
"attachments": ,
"body": " Verification Code : 9906 Enter the code to sign up! Keep this code to yourself, and no other action is required. "
}
how do I want to retrieve the submitted code that appears from the json response?
I want to get just the response code to put in the variable value
Upvotes: 0
Views: 120
Reputation: 5917
I assume that you want to get 9906
from body
part.
const res = pm.response.json();
let body = res.body;
const regex = /\d{4}/gm;
//console.log(regex.exec(body)[0]); //9906
pm.environment.set("code", regex.exec(body)[0]);
Upvotes: 1