I have an csv file that contains phone number 8005551212 and variable name = {{phone}}. I would like to add a prefix = +1 thru postman rather than edit/reformat/update the csv file.
I need to add prefix +1 in order to pass +18005551212 to an API to send an SMS.
How to I add or hardcode +1 to the variable {{phone}}?
I have tried a couple of suggestions to no avail.
Here is what I am attempting with no success.
Import a comma delimited CSV using Run Collection \ Select File \ Import
column heading = Name,Contact
row data = John Doe,8005551212
The Contact value has “8005551212” as a string value (exported from excel as string column).
Body in POST Request:
{
“to” : {{Contact}},
“from” : “+18775551212”,
“text” : “Hey, check this out!”,
“applicationId” : “EnterAppIicationIdHere”,
“tag” : “This is test message”,
“priority” : “default”
}
When the POST is sent I want to be sure to pre-pend “+1” when the CSV is being read and processed by POST
so that the value of {{Contact}} = “+18005551212”
I am trying this pre-request script with no luck. I think I have the syntax right but getting Property Assignment Expected
You can’t have the same name for the header in the CSV file and the global variable you are trying to set in the pre-request script. (You can but the local scope will win, which will be the CSV file entry). Just call them something else so you know what’s what.
You can reference the entry in the CSV file by prepending data to the variable\header name.
One line in your pre-request script which will set a collection variable with your updated phone number that can be used in the request, using the standard methods {{phone}}.
Collection Variable, not Global. (Pretty sure this variable doesn’t need to be seen by all of your collections in Postman).
Please note, you can’t use {{variable}} in the tests tab or pre-request scripts. It only works like that in the body, headers and params section. You either need to use pm.collectionVariables.get(“Phone”) or if referencing a line in the CSV file, by using data.headername
Postman Echo doesn’t really like the “+1” at the beginning of the string and doesn’t actually return it properly in the response. But hopefully your API will be more accepting.