Postman and Newman: email verification test collection
Postman collections are a common way to share API checks, and a sign-up flow is one of the first things a team wants to run in CI. The awkward part is the email step: Postman can call your sign-up endpoint, but something has to read the message. This guide gives a complete Postman collection (format v2.1) with four requests. It signs up with a unique AssertInbox address, waits for the email, verifies with the code from the email and cleans up. A Newman command runs the same collection in CI.
How it works
Mail sent to <namespace>.<tag>@assertinbox.com is stored for your key. GET /v1/wait long-polls for up to 25 seconds and returns the newest matching message as JSON, with otp, magic_link and links already extracted. Messages are deleted after 24 hours. A unique tag per run is a private inbox, so two runs never read each other's mail.
Get an API key
Get a key in a click at /start. One request creates a key and your private namespace, with no email address or card. The key is shown once, so keep it in your secret store. You need the api_key and the namespace for the collection variables below. Use inboxes only for services you own or control; see the terms. Limits and error codes are on the limits page.
The collection
Save this as signup-email.postman_collection.json and import it in Postman, or run it with Newman. The appUrl variable and the routes /api/signup and /api/verify are placeholders for your own app; use them only against an app you own. Leave assertinboxKey and namespace empty in the file and supply them at run time, so no secret is saved in the collection.
{
"info": {
"name": "Sign-up email verification",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"variable": [
{
"key": "appUrl",
"value": "http://localhost:3000"
},
{
"key": "namespace",
"value": ""
},
{
"key": "assertinboxKey",
"value": ""
},
{
"key": "tag",
"value": ""
},
{
"key": "email",
"value": ""
},
{
"key": "otp",
"value": ""
},
{
"key": "attempts",
"value": "0"
}
],
"item": [
{
"name": "1 Sign up",
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
"const tag = 'pm-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 8);",
"pm.collectionVariables.set('tag', tag);",
"pm.collectionVariables.set('email', pm.collectionVariables.get('namespace') + '.' + tag + '@assertinbox.com');",
"pm.collectionVariables.set('attempts', '0');"
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"pm.test('sign-up accepted', function () {",
" pm.response.to.have.status(201);",
"});"
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\"email\": \"{{email}}\", \"password\": \"correct-horse-battery-staple\"}"
},
"url": {
"raw": "{{appUrl}}/api/signup",
"host": [
"{{appUrl}}"
],
"path": [
"api",
"signup"
]
}
}
},
{
"name": "2 Wait for the email",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"const attempts = Number(pm.collectionVariables.get('attempts')) + 1;",
"pm.collectionVariables.set('attempts', String(attempts));",
"if (pm.response.code === 408 && attempts < 3) {",
" postman.setNextRequest(pm.info.requestName);",
"} else {",
" pm.test('an email arrived', function () {",
" pm.response.to.have.status(200);",
" });",
" const mail = pm.response.json();",
" pm.test('the email has a code', function () {",
" pm.expect(mail.otp).to.match(/^[0-9]{4,8}$/);",
" });",
" pm.collectionVariables.set('otp', mail.otp);",
"}"
]
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{assertinboxKey}}",
"type": "string"
}
]
},
"method": "GET",
"header": [],
"url": {
"raw": "https://assertinbox.com/v1/wait?tag={{tag}}&timeout=25&subject=verify",
"protocol": "https",
"host": [
"assertinbox",
"com"
],
"path": [
"v1",
"wait"
],
"query": [
{
"key": "tag",
"value": "{{tag}}"
},
{
"key": "timeout",
"value": "25"
},
{
"key": "subject",
"value": "verify"
}
]
}
}
},
{
"name": "3 Verify with the code",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"pm.test('the code verifies the account', function () {",
" pm.response.to.have.status(200);",
"});"
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\"email\": \"{{email}}\", \"code\": \"{{otp}}\"}"
},
"url": {
"raw": "{{appUrl}}/api/verify",
"host": [
"{{appUrl}}"
],
"path": [
"api",
"verify"
]
}
}
},
{
"name": "4 Clean up",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"pm.test('messages deleted', function () {",
" pm.response.to.have.status(200);",
"});"
]
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{assertinboxKey}}",
"type": "string"
}
]
},
"method": "DELETE",
"header": [],
"url": {
"raw": "https://assertinbox.com/v1/messages?tag={{tag}}",
"protocol": "https",
"host": [
"assertinbox",
"com"
],
"path": [
"v1",
"messages"
],
"query": [
{
"key": "tag",
"value": "{{tag}}"
}
]
}
}
}
]
}
What each request does
- 1 Sign up. The pre-request script builds a unique tag from the time and a random suffix, stores the address in the
emailvariable and resets the retry counter. The request posts the address to your app and the test script asserts the status. - 2 Wait for the email. A GET to
/v1/waitwith the tag, a 25-second timeout and a subject filter, authenticated with the key as a bearer token from the collection variable. The test script stores theotpin a variable and asserts it looks like a code. - 3 Verify with the code. Posts
{{email}}and{{otp}}back to your app and asserts the status. - 4 Clean up. Deletes the messages for the tag. Run it last so the inbox does not keep test mail.
The 408 retry
If no email arrives within the timeout, the API returns 408 timeout. That is normal for a slow queue, so the test script of request 2 calls postman.setNextRequest with its own name and tries again, at most three times in total. After that, the status assertion fails with the real response. This loop works in the Collection Runner and in Newman; a single manual Send runs the request once.
Run it with Newman in CI
Newman is the command-line runner for Postman collections. Pass the key and namespace on the command line from your CI secrets, never from the file:
npm install --global newman
newman run signup-email.postman_collection.json \
--env-var "assertinboxKey=$ASSERTINBOX_KEY" \
--env-var "namespace=$ASSERTINBOX_NAMESPACE" \
--env-var "appUrl=https://staging.example.com"
Newman exits with a non-zero status when any assertion fails, so a CI job fails with it. To run several sign-ups in parallel, start several Newman processes; each generates its own tag. Avoid running the same collection twice with the tag set by hand, because two runs would then share one inbox.
Troubleshooting
- Request 2 returns 401. The
assertinboxKeyvariable is empty or wrong. Check the--env-varvalue and that the variable name matches. - Request 2 returns 408 three times. The app did not send the email, or sent it to another address. Print the
emailvariable in the Postman console and compare it with the app's logs. - Request 2 returns 429. The key used its 2,000 requests for the day;
GET /v1/meshows usage. - The otp assertion fails. The email has no recognisable code. Read the
textfield of the response and extract it yourself, or usemagic_linkinstead. - The variable is empty in request 3. Collection variables are set by scripts at run time. Run the whole collection in order rather than sending request 3 alone.
Next steps
For unique tags, the trigger-then-wait order, retries and cleanup in one place, read Reliable email tests. More stacks are on the guides page.