Postman
Table of Contents
Postman tips
The last time I checked, it wasn’t available through pacman.
paru -S postman-bin
Setting a string from response body as a collection variable - JSON response
Script to read fields from a JSON response and set it as a collection variable that can be used in the subsequent steps:
var jsonData = JSON.parse(responseBody);
pm.collectionVariables.set("quoteId", jsonData.data.quoteId);
var jsonData = JSON.parse(responseBody);
pm.collectionVariables.set("access_token", jsonData["access_token"]);
It looks like responseBody
is deprecated. Use pm.response.text()
instead.
var jsonData = pm.response.json();
pm.collectionVariables.set("access_token", jsonData["access_token"]);
Filtering response objects for a specific one
var jsonData = pm.response.text();
var tasksCalendarId;
_.each(pm.response.json().items, (item) => {
if(item.summary === 'Tasks') {
console.log(item)
tasksCalendarId = item["id"];
}
})
console.log(tasksCalendarId)
pm.collectionVariables.set("tasksCalendarId", tasksCalendarId);
Using a collection variable in headers
Authorization:Bearer {{access_token}}
Setting a string from response body as a collection variable - SOAP response
Script to read fields from a SOAP response and set it as a collection variable that can be used in the subsequent steps:
var parseString = require('xml2js').parseString;
var stripPrefix = require('xml2js').processors.stripPrefix;
parseString(responseBody, { tagNameProcessors: [ stripPrefix ] }, function(err, js) {
if(err) throw err;
var companysQuoteNumber = js.Envelope.Body[0].rateResponse[0].response[0].HomePolicyQuoteInqRs[0].PersPolicy[0].QuoteInfo[0].CompanysQuoteNumber[0];
pm.collectionVariables.set("companysQuoteNumber", companysQuoteNumber);
});
(A simpler way is to use xml2json but it will not remove the namespaces from the json and if the namespaces are dynamically changing, it can be a problem)
Alternatives to Postman
- Hoppscotch
- A free and open-source alternative that supports designing and debugging REST, GraphQL, and WebSocket APIs. It also offers real-time collaboration features and can import collections from Postman, Insomnia, OpenAPI, or GitHub Gist.
- Insomia.
- While Insomnia does require an account, they do support local-only storage of data.
- For cloud-hosted content, they have explicitly implemented features (such as end-to-end encryption) to ensure that their servers never see any sensitive information.
- If even this amount of connectivity makes you nervous, there is a fork of Insomnia that removes these features: Insomnium.
- Bruno.
- Also very popular, and offline only.
- Visual Studio (including rich support for secrets),
- PowerShell’s Invoke-RestMethod,
- Curl, etc.
Insomnia and Bruno support import from Postman.