Guide

Bringing collections in

A collection you already have becomes .stamp files in one step. Postman, Insomnia, Bruno, a HAR file, curl commands and OpenAPI documents all come in the same way: File ▸ Import… (⇧⌘I) in the app, stamp import in the terminal. The rest of this section follows one Postman collection all the way through, because what arrives needs two small edits whichever way you brought it in.

The usual first import is a Postman collection together with the environments that go with it. Export all of them, then name them in one command. The order does not matter, and -o is the folder to write into.

stamp import Blog.postman_collection.json staging.json production.json -o blog

  created blog/Auth.stamp
  created blog/Posts.stamp
  created blog/environment.stamp
  created blog/environment.local.stamp
Imported Blog (Postman collection): 2 requests in 2 files

One file per folder of the collection. This is blog/Auth.stamp, the whole file:

# Blog · Auth
# Imported from a Postman collection; edit freely.

### Log in
POST {{baseUrl}}/auth/login
Content-Type: application/json

{ "username": "emilys", "password": "emilyspass" }

> assert status == 200
> set token = body.accessToken

The two > lines were a Postman test script. The request that needs that token is one file over. This is blog/Posts.stamp without its two comment lines at the top:

### List posts
@auth bearer {{token}}
GET {{baseUrl}}/posts?limit={{limit}}

> assert status == 200

Line by line, this is what came across:

a folder in the collectiona .stamp file, named after it
a request titlethe ### line, and the name other requests use: Log in becomes logIn
pm.response.to.have.status(200)> assert status == 200
pm.environment.set("token", …)> set token = body.accessToken
bearer auth on the request@auth bearer {{token}}
collection variablesa vars { } block in environment.stamp

The two Postman environments became the values of one dimension, so the whole import points at staging or at production by choosing a value:

# environment.stamp
dimension environment = staging, production

vars {
  baseUrl = "https://dummyjson.com"
}

vars environment=staging {
  limit = "5"
}

vars environment=production {
  limit = "25"
}

The API key was not written there. Anything whose name reads like a credential goes to environment.local.stamp, wrapped in secret() so it is masked in output, and that file is added to .gitignore the first time it is written.

# environment.local.stamp
vars environment=staging {
  apiKey = secret("sk_test_8f2a91c4")
}

Nothing has been sent yet. stamp check parses the folder and reports mistakes without touching the network, which is the first thing to run on an import.

stamp check blog

✓ 3 files, 2 requests

Then run it. The requests in a folder run in order, in one session, so the token the login stored is there for the request that needs it.

stamp run blog

→ POST https://dummyjson.com/auth/login  Auth.stamp › logIn
  200 OK  112 ms  930 bytes
  ✓ status == 200

→ GET https://dummyjson.com/posts?limit=5  Posts.stamp › listPosts
  200 OK  59 ms  3 KB
  ✓ status == 200

✓ 2 requests, 2 assertions

Naming a dimension value on the command line switches environment, and the limit that comes back with it:

stamp run blog environment=production

→ POST https://dummyjson.com/auth/login  Auth.stamp › logIn
  200 OK  104 ms  930 bytes
  ✓ status == 200

→ GET https://dummyjson.com/posts?limit=25  Posts.stamp › listPosts
  200 OK  59 ms  12 KB
  ✓ status == 200

✓ 2 requests, 2 assertions

Two things to fix afterwards

An import is a starting point, not a finished workspace. Two edits are worth making before anything else.

Say what a request depends on. Postman has no way to record that listing posts needs a login first; it relies on you running the collection top to bottom. So listPosts on its own fails:

stamp run blog listPosts

→ listPosts  Posts.stamp › listPosts
  ✗ line 6: unknown variable 'token'

✗ 1 request, 1 failed

One line fixes it for good. @needs logIn runs the login first, once per session, whichever way the request is reached. This is the top of Posts.stamp after the edit, not a file on its own: the request it names lives next door in Auth.stamp.

### List posts
@needs logIn
@auth bearer {{token}}
GET {{baseUrl}}/posts?limit={{limit}}

Turn numbers back into numbers. Every Postman variable is text, so limit arrived as "5". Comparison is strict, and 5 == "5" is false, so a check that compares it to a number needs the quotes taken off in environment.stamp.

The other formats

Each takes the same shape of command. Only the input differs.

stamp import export.json -o api       # an Insomnia export, JSON or YAML
stamp import ./bruno-folder -o api    # Bruno, .bru or OpenCollection YAML
stamp import traffic.har -o api       # saved from a browser's network tab
stamp import openapi.yaml -o api      # OpenAPI 3 or Swagger 2
pbpaste | stamp import - -o api       # curl commands, straight off the clipboard
HAROnly API calls are kept. It says how many pages, scripts, images and fonts it left out.
OpenAPIOne file per tag, one request per operation, named after its operationId. Parameters become variables filled with the document's examples, security schemes become @auth lines, and the first documented 2xx becomes an assertion.
curlA file of commands, or - to read them from standard input.

Import never writes over a file that is already there; it stops and asks for another folder, so pick a fresh one with -o and move across what you want. It also leaves alone every variable the workspace already declares, so an import cannot change what an existing request sends.

Script lines with no equivalent are kept as comments above the request. Nothing is dropped quietly:

### Place an order
# Postman test script lines that weren't converted:
#   console.log(pm.response.json());
#   postman.setNextRequest('Something else');
POST {{baseUrl}}/carts/add

> assert status == 200
> set cartId = body.id

In the app

  1. Choose File ▸ Import… (⇧⌘I). The panel takes several files at once, and folders as well, so a collection and its environments go in together.
  2. The requests land in a new folder inside the open workspace, named after the collection, and the sidebar selects that folder when it finishes.
  3. A message says what happened: how many requests and in which folder, which dimension the environments became and with what values, what went to environment.local.stamp, which variables the workspace already had and were therefore left alone, and anything else to look at.
  4. Open a request and click the selector in the row with its title, the one reading environment staging after an import, and pick the other value. That is how the whole import points at staging one minute and production the next.
  5. For one request rather than a collection, copy it with Copy as cURL in a browser's developer tools and use File ▸ Paste curl as Request (⌥⌘V). It goes into the selected file, or a new one when nothing is selected, and the request it made is then selected.

Nothing has been sent at this point, which is the useful part: an import is read and repaired before a single request goes out. Switch a file to Source and anything that does not parse is underlined where it is, with the first one named under the editor. The two edits above, the @needs line and the quotes around a number, are the ones worth making straight away.

Next: Variables and dimensions for the environments the import created, Secrets for the keys it moved out of git, and Requests for what to write once the import is yours.

Updated

Back: Requests Next: Variables and dimensions