Configuration

Assign variables

Capture values from responses, headers or request bodies into Postman collection variables to chain requests in Portman.

assignVariables sets Postman collection variables from a response body, response header, request body or a fixed value after a request runs. Combined with overwrites, it chains requests together, for example reusing the ID of a created record in the get, update and delete requests.

Example: create, then reuse the ID

json
{  "version": 1.0,  "assignVariables": [    {      "openApiOperation": "POST::/crm/leads",      "collectionVariables": [        {          "responseBodyProp": "data.id",          "name": "leadsAdd.id"        }      ]    }  ],  "overwrites": [    {      "openApiOperation": "GET::/crm/leads/{id}",      "overwriteRequestPathVariables": [        {          "key": "id",          "value": "{{leadsAdd.id}}",          "overwrite": true        }      ]    },    {      "openApiOperation": "DELETE::/crm/leads/{id}",      "overwriteRequestPathVariables": [        {          "key": "id",          "value": "{{leadsAdd.id}}",          "overwrite": true        }      ]    }  ]}

Make sure the create request runs before the requests that use the variable. You can control the request order with orderOfOperations in globals.

Options

PropertyDescription
openApiOperationIdOpenAPI operationId for which the variables are set.
openApiOperationIdsArray of operationIds.
openApiOperationMethod and path, supports wildcards.
excludeForOperationsOptional. Operations to skip.
collectionVariablesArray of variables to set.

Each item in collectionVariables uses one source and an optional name:

PropertyDescription
responseBodyPropTake the value from this response body property. Use . to store the whole body.
responseHeaderPropTake the value from this response header.
requestBodyPropTake the value from this request body property.
valueA fixed value. Supports template expressions.
nameOptional. The Postman variable name. Default: <operationId>.<varProp>. Supports template expressions.
json
"assignVariables": [  {    "openApiOperation": "GET::/crm/leads/{id}",    "collectionVariables": [      { "responseBodyProp": "data.company_name" },      { "responseBodyProp": ".", "name": "leadResponse" },      { "responseHeaderProp": "Operation-Location" }    ]  },  {    "openApiOperationId": "leadsAdd",    "collectionVariables": [      { "requestBodyProp": "company_name", "name": "leadsAdd.company_name" }    ]  }]

Template expressions

Variable names and overwrite values can use template expressions, so one rule can cover many operations. Using the operation GET /crm/leads with operationId leadsAll and tags Leads, CRM:

ExpressionResult
<operationId>leadsAll
<method>GET
<path>/crm/leads
<pathRef>GET::/crm/leads
<opsRef>The operationId, falling back to the pathRef when there is none.
<tag>First tag, Leads
<tag1>, <tag2>, <tagn>The nth tag.
<pathPart1>, <pathPart2>, <pathPartn>The nth path segment: crm, leads.

Generic chaining for every resource, in YAML:

yaml
globals:  variableCasing: snakeCaseassignVariables:  - openApiOperation: POST::*    collectionVariables:      - responseBodyProp: data.id        name: "<tag>Id"overwrites:  - openApiOperation: "*::/crm/*/{id}"    excludeForOperations:      - POST::*    overwriteRequestPathVariables:      - key: id        value: "{{<tag>Id}}"        overwrite: true

After POST /crm/leads, the ID is stored as leads_id (the <tag>Id expression, converted by variableCasing), and every request on /crm/leads/{id} uses it. The same happens for contacts with contacts_id.

Logging

Assigned variable names are logged in the Portman and Postman console. Turn Portman's logging off with --logAssignVariables false.

In variations

assignVariables can also be defined inside a variation, without a target.