I have a request and I want to parameterize some fields in the Body, below is an example. I appreciate any help.
Request:
http://website/request
Body: (I want to parametrize the first and last names only)
request": {
“FirstName”: “{{chris}}”,
“LastName”: “{{tom}}”,
“Email”: “[email protected]”,
Hi Chris,
The way you have that setup should work fine:
Body:
{
"FirstName":"{{first_name}}",
"LastName":"{{last_name}}"
}
You then just need to add first_name
and last_name
as variables either:
- In an Environment
- As Global Variables
See Intro to environments and globals on our Learning Center for more info.
You can also set them programmatically from the Sandbox, using pm.variables.set('name','value')
. This will declare a run-scoped variable with whatever value you want — useful when you need to set this value based on (e.g.) response data from another request.
Happy I could help!
Yep! Try Postman Echo: https://docs.postman-echo.com/
Hey John, I believe I finally got the parametrization working. What I’d like to do next is see which row is being used for each run. Using the CSV File example below, when I use the Collection Runner, in the output, I’d like to see something like “Test Data: InvalidEmail.”
If you know of a better way to do this then plz let me know.
CSV File:
LOEmail,BranchNumber,AppId,BorrowerFirstName,BorrowerLastName
HappyPath,[email protected],331,9464099213815567,Chris,rao
InvalidEmail,[email protected],331,9464099213815567,Chris,rao
Hi @christopherktom
Long delay or follow-up here, but in case you haven’t found it yet you can use pm.info.iteration
to get the row number of the CSV.
But, you can totally do it your way by using:
console.log(pm.iterationData.get('LOEmail'));
Which will log the value you noted to the console (Command + Option + C
on Mac)