user7605119
user7605119

Reputation:

Postman send multiple requests

I've got a PATCH request that looks like this: {{host}}/api/invoice/12345678/withdraw host is a variable determining the environment.

For this request I need to add a unique authorization token. auth token

The problem is I need to send dozens of such requests. Two things change for each request:

  1. id of invoice (for this case is '12345678')
  2. auth token (herebetoken1).

How can I automate it?

Upvotes: 1

Views: 21499

Answers (2)

oktaykcr
oktaykcr

Reputation: 376

You can use Postman Runner for your problem. In Runner, you can send specified requests in specified iterations and delay with data (json or csv file).

For more info, I suggest you take a look at the links below.

Request: Example Request

Runner: runner

Data: (You can choose one of them)

Json Data: (data.json)

json data

csv Data: (data.csv)

csv

Preview Data in Runner:

preview

Result: result

Upvotes: 1

PDHide
PDHide

Reputation: 19939

use the below pre-request script , and call replace id in url and auth in authorization with {{id}} and {{token}} variables . Use collection runner to execute it .

Replace the hashmap with what you requires

hashmap = {
    "1234": "authtoken1",
    "2222": "authtoken2"
}

pm.variables.get("count") === undefined ? pm.variables.set("count", 0) : null

let keyval = Object.entries(hashmap)
let count = pm.variables.get("count")
if (count < keyval.length) {
    pm.variables.set("id", keyval[pm.variables.get("count")][0])
    pm.variables.set("token", keyval[pm.variables.get("count")][1])
    pm.variables.set("count", ++count)
    keyval.length===count? null:postman.setNextRequest(pm.info.requestName)
}

 

Example collection:

https://www.getpostman.com/collections/43deac65a6de60ac46b3 , click inport and import by link

Upvotes: 0

Related Questions