Templates

Pre-request script setup

Prepare dynamic data before requests run, from iteration data or computed values.

scriptsvariablesoverwrites

What it does

Sets a default status from Newman iteration data before every request with a collection pre-request script, and computes a unique lead name right before the create request. The request body overwrites then use those variables, so each run sends fresh data.

portman-config.json
{  "version": 1,  "globals": {    "collectionPreRequestScripts": [      "pm.collectionVariables.set('status', pm.iterationData.get('status') || 'open')"    ]  },  "operationPreRequestScripts": [    {      "openApiOperationId": "leadsAdd",      "scripts": [        "pm.collectionVariables.set('leadName', 'Lead ' + Date.now());"      ]    }  ],  "overwrites": [    {      "openApiOperationId": "leadsAdd",      "overwriteRequestBody": [        {          "key": "name",          "value": "{{leadName}}",          "overwrite": true        },        {          "key": "status",          "value": "{{status}}",          "overwrite": true        }      ]    }  ],  "tests": {    "contractTests": [      {        "openApiOperation": "*::/crm/*",        "statusSuccess": {          "enabled": true        }      }    ]  }}

Run it

terminal
$ npx @apideck/portman -l ./openapi.yaml -c ./portman-config.json -b http://localhost:3050 -n true -d ./newman-data.json

Notes

  • Scripts can also be loaded from a file with the file: prefix, for example "file:./scripts/setup.js".
  • To send a variable as a number or boolean in the body, wrap it in three braces, like "{{{amount}}}".