--- title: Importing Expectations from HAR & Postman description: Import expectations into MockServer from HAR (HTTP Archive) or Postman Collection files via a single PUT /mockserver/import request, with format auto-detection. shortTitle: Import HAR / Postman layout: page pageOrder: 3.5 section: 'Mock Server' subsection: true sitemap: priority: 0.7 changefreq: 'monthly' lastmod: 2026-06-02T00:00:00+00:00 ---

MockServer can import expectations directly from HAR (HTTP Archive) files and Postman Collection v2.x files. This lets you record real HTTP traffic in your browser or Postman, then replay it through MockServer without writing expectations by hand.

Common use cases:

 

Import Endpoint

Send a PUT request to /mockserver/import with the HAR or Postman JSON document as the request body. MockServer creates one expectation per entry (HAR) or per saved example response (Postman) and returns 201 Created with the generated expectations as JSON.

 

Format detection

MockServer auto-detects the format from the JSON structure:

You can also override auto-detection with the format query parameter:

Query parameter Value Description
format har Force HAR parsing
format postman Force Postman Collection parsing

If auto-detection fails and no format parameter is provided, MockServer returns 400 Bad Request with a message suggesting you specify the format explicitly.

Insomnia collections are not supported. Attempting to import an Insomnia export returns a clear error message. Convert Insomnia collections to HAR or Postman format first.

 

Importing from HAR

Each entry in the HAR's log.entries[] array produces one expectation. The request matcher uses the method, path, and query parameters from the recorded request. The response uses the recorded status code, headers, and body.

Volatile header filtering

Not all recorded headers make sense in a mock expectation. MockServer automatically filters out volatile headers that would over-constrain matching or produce stale responses:

Non-volatile headers (such as Content-Type, Accept-Language) are preserved and included in the generated expectations.

Request body handling

When a HAR entry has postData.text, it is included in the request matcher if the body is reasonably sized (under 4 KB). Larger request bodies are omitted from matching to keep expectations permissive.

Base64 response bodies

HAR files sometimes encode response bodies as Base64 (indicated by content.encoding: "base64"). MockServer automatically decodes these back to plain text for the generated response body.

curl -v -X PUT "http://localhost:1080/mockserver/import" \
  -H "Content-Type: application/json" \
  --data-binary @traffic.har

Or explicitly specify the format:

curl -v -X PUT "http://localhost:1080/mockserver/import?format=har" \
  -H "Content-Type: application/json" \
  --data-binary @traffic.har

MockServer returns 201 Created with the generated expectations as JSON.

 

Importing from Postman

MockServer supports Postman Collection v2.0 and v2.1 formats. Collections are walked recursively, so requests inside folders are imported correctly.

For each request item that has saved example responses (the response[] array), one expectation is created per example. Requests without saved examples are skipped (with a count logged), since there is no response to mock.

The Postman url field is handled whether it appears as a plain string or as the structured object format with path[] and query[] arrays.

curl -v -X PUT "http://localhost:1080/mockserver/import?format=postman" \
  -H "Content-Type: application/json" \
  --data-binary @my-collection.postman_collection.json

MockServer returns 201 Created with the generated expectations as JSON.

 

What gets generated

Each imported expectation is assigned a stable ID based on the source format and entry index (e.g. har-0, har-1, or postman-0-get-users). Re-importing the same file updates the existing expectations in place rather than creating duplicates.

The generated expectations use unlimited times and unlimited time-to-live, so they will match repeatedly until cleared or reset. You can modify individual expectations after import using the standard PUT /mockserver/expectation endpoint.

 

Error responses

Status Cause
201 Import succeeded; body contains the generated expectations as JSON
400 Empty body, invalid JSON, unrecognised format, or missing required structure (log.entries for HAR, info/item for Postman)