Skip to content

Import mocks from a HAR, Postman or curl

Before you begin

Role
Editor or higher.
You need
  • A project
  • A HAR file, a Postman v2.0 or v2.1 collection, or curl commands with the output each printed

Turn requests you already recorded, in a browser, in Postman or with curl, into mocks that answer exactly what the real API answered. Nothing is sent to an AI model, and nothing is guessed: each mock copies one recorded request and its response, unless you choose to tell overlapping examples apart.

  1. On the project’s Mocks tab, select the arrow beside New mock (More ways to add mocks), then Import. A project with no mocks shows Import as a button of its own.

  2. Under Choose a source, select a file in Upload a file, or paste the source into the box below it: a HAR or Postman collection’s JSON, or curl commands followed by what each printed. Get the source says how to export each one.

  3. Optionally, enter a Base path (optional) such as /v1, to put in front of every imported path, and add up to five Tags for every imported mock (optional).

  4. Select Preview import. Nothing is created yet. The preview names the format it read, such as HAR or Postman collection and the collection’s name, and counts the entries it read, how many are importable and how many are ticked.

  5. Read the Entries. Each import entry is a request with its response, ticked when it is imported by default. Tick the ones you want and untick the others; Use the defaults goes back to the preview’s choice, and Tick none clears every box.

  6. If the preview lists Overlapping examples, choose how each group becomes mocks; see Overlapping examples.

  7. Read the Mocks the plan would create. Open Response under a mock to see its headers and the start of its body.

  8. Select Apply import.

If you change a choice after the preview, such as a box or the base path, the page says Your choices changed since this preview. Preview again to apply them. Select Preview again: the import applies only the plan it showed you.

A message says how many mocks were imported, such as 12 mocks imported, and Inactive until you activate them. Review them below. Every imported mock is Inactive, so none of them answers a request until you activate it.

If every ticked entry already has an identical mock in the project, nothing is created and the message is Nothing to import.

Review the import opens on the page. It lists the mocks this import created, with nothing selected, and shows each one’s status and what it matches.

  1. Select Response under a mock to read what it answers, and again to fold it away.

  2. Tick the mocks to serve, or Select this page to tick the page’s mocks. Ticks stay when you change page.

  3. Select Activate.

If a ticked mock answers the same requests as another ticked mock, or as an active mock already in the project, MockHub first asks Activate mocks that answer the same requests? and names them. With both active, which one answers is not defined. Select Activate anyway, or cancel and untick one of them.

A message such as Activated 12 mocks confirms it, and those mocks are unticked. If MockHub refuses part of the way through, for example at the plan’s limit of active mocks, the message says how many it activated, such as Activated 40 mocks, then stopped, and why; the mocks it did not reach stay ticked.

With mocks ticked you can also select Deactivate, or Ask AI… to open the assistant on at most 50 of them, for example to make their data vary. Reused lists the entries an identical mock already stood for; those mocks are left exactly as they were.

The review stays in that browser tab while you open a mock to edit it and come back. Select Done reviewing to close it.

A HAR is the network log a browser or a tool exports. Record the requests, then export them:

  • Chrome and Edge: in the developer tools’ Network panel, export the requests as HAR. The sanitized export, which leaves out cookies and authorization headers, is enough.

  • Firefox: in the Network panel, save all requests as HAR.

  • Safari: in the Web Inspector’s Network tab, export the requests as HAR.

  • Playwright: record with recordHar and keep the bodies in the file:

    const context = await browser.newContext({
    recordHar: { path: 'orders.har', content: 'embed' },
    });

    With content: 'omit' or 'attach', the bodies are not in the file, and those entries cannot be imported. A ZIP HAR cannot be imported.

  • Charles and Proxyman: export the session as HAR.

A HAR usually holds requests to several hosts. When it does, Hosts lists each one with its counts: untick a host to leave its requests out.

Export the collection as Collection v2.1 (v2.0 is read too). The import reads the saved examples of each request, not the request itself: a request without a saved example is not imported, so save one in Postman first. Each example becomes a mock named after the request and the example, such as Get order / Not found, tagged with the folders it is in.

A collection’s {{baseUrl}} and other variables come from the collection and its folders. To give a value the collection does not have, select Add a variable under Variables (optional) and enter its name and value, such as baseUrl and https://api.example.com/v1. These come before the collection’s own values.

To take the values from a Postman environment, export the environment from Postman, preview the collection, then select the file in Or take them from a Postman environment file. The file is read in your browser and is not uploaded: only the enabled values the collection uses become variables, each replacing a variable of the same name. A message says how many were added, such as One variable added from staging.json., and how many other values were left out. Select Preview again to use them. An environment file is not a collection, so it cannot be the source itself.

An example whose host, or a whole path segment, is a variable no value was given for is not ticked by default: it would match more requests than its author meant. Pre-request scripts, tests, globals and dynamic variables such as {{$guid}} are never run.

Run each command with -i, so curl prints the response’s status line and headers before the body, and paste the commands together with what they printed:

Terminal window
$ curl -i https://api.example.com/orders/42
HTTP/2 200
content-type: application/json
{"id": 42, "status": "shipped"}

The import also reads the output of -v, and of a command without either option when what it printed is one JSON value; that one is imported as a 200. Lines may start with a $ prompt. The commands are read, never run: no file or variable they name is opened or expanded.

A command copied from a browser’s Copy as cURL has no output under it. The import does not invent a response, so such a command is not ticked by default: tick it to import an empty 200 for its method and path. If you are an Admin, Generate responses with AI opens AI generation on the same paste, to draft the responses instead.

Each ticked entry becomes one mock that matches the request’s method and path, as recorded, and answers with the recorded status, headers and body. Query parameters, request headers and request bodies are not matched, so every request to that method and path gets the answer, unless you choose otherwise under Overlapping examples. A mock is named after its request and status, such as GET /orders/42 200, and is tagged with your tags, the format (har, postman or curl) and the host or the Postman folders.

Every imported mock is served as written: its response is never evaluated as a template, even when the body contains {{…}}. It keeps this when the project’s response templating setting changes, in a configuration document and in a reusable pack.

A text/event-stream response is imported as a stream with a 300 ms first chunk and 30 ms gaps, since no source records when each chunk arrived.

For a HAR or curl, one entry per method and path is ticked by default: the latest successful response, or the latest one if none succeeded. Postman ticks the lowest successful example of each request. The other entries of the same request are importable, with Not ticked by default: Another capture of the same request.

For a HAR or curl, Match identifiers in paths as any value makes /orders/42 and /orders/43 one mock for /orders/{id}, a Path with parameters that answers any order with the latest response. A path with several identifiers is named {id}, {id2} and so on; a Postman path variable such as :orderId keeps its name. Off, each path is matched as recorded.

Some entries are importable but not ticked by default, and say why:

The entry says Why
Not ticked by default: A page asset (HTML, CSS or script) A page, stylesheet or script the browser loaded, rarely what an API mock needs
Not ticked by default: Another capture of the same request Another entry of the same method and path is ticked
Not ticked by default: No response under the command A curl command with nothing printed under it; ticked, it imports an empty 200
Not ticked by default: Text not checked for fields to redact Plain text or HTML, which no field can be redacted from. It is marked Review: read it for secrets before you tick it
Not ticked by default: An unresolved variable A Postman variable with no value stands for a host or a whole path segment. It is marked Review: it matches broadly

An entry that cannot be imported cannot be ticked, and says Cannot be imported: with the reason, such as The exporter left the body out, A binary body, Answered from the browser cache (304), A CORS preflight, which the gateway answers itself, The body is over the plan’s limit or A curl option the import does not model.

Examples of one method and path, such as GET /orders?status=open and GET /orders?status=closed, would become mocks that answer the same requests. When a file holds such examples, the preview lists them under Overlapping examples, one group per path, and each group starts on Keep separate: one mock per ticked example, matching the path alone, as described above.

Choosing another option ticks the examples it needs, says which under it (Also ticks …) and previews the import again. To undo a choice, select Keep separate again; the examples stay ticked.

Match on status (named after the actual parameter) makes one mock per value, each matching the path and exactly that value of the parameter, such as GET /orders?status=open. The option lists each value it will save in the mock, with the status recorded for it. Other query parameters are not matched, so GET /orders?status=open&page=2 gets the open answer.

A parameter is offered only when every example records it once, with a value, and each value always got the same answer. It is never offered for a parameter that redaction treats as a credential, such as api_key, or for one that appears twice in a request. A curl command that sends its query with -G or --url-query, and a Postman URL that lists its query only in separate parameters, are not offered one: the address alone does not show the query that was sent.

A request with a value no mock has, such as status=shipped, is answered by whatever else in the project matches it, or not at all. A mock for the same path that matches no query parameter also answers these requests; the preview names it, and with both active, which one answers is not defined.

Combine as named responses makes one mock for examples of the same request, such as several saved examples of one Postman request, with one response variant per different answer. Identical answers become one response. Each response is named after its Postman example, or otherwise its status, and its key is shown beside it.

Once chosen, pick the Default response: the one a plain request gets. Any other response is served to a request that asks for it with a request override; after the import, the review shows the X-MockHub-Response header to send for each, with a button to copy it.

The import does not read request headers or bodies, so examples offered together may have differed there; the mock still matches only the method and path. A group with more than 50 different answers cannot be combined: a mock holds at most 50 responses.

The planned mock says, for example, 2 examples → 1 mock with 2 responses, default “Refunded”., and the review lists it once, so you activate it once.

Unticking an example a choice needs, leaving out its host or selecting Use the defaults drops the choice, and the page says which one went. If a choice no longer holds when the import is previewed, the page says One choice about overlapping examples no longer holds with the reason, and Drop it and preview again removes it and keeps your other choices and ticks.

The import applies the project’s capture redaction, the same rules as recording a real API:

  • In JSON, XML and form bodies, the values of fields such as password and token, and of the fields in the project’s Body keys to redact in captures, are replaced. The rest of a JSON body stays byte for byte as recorded.
  • Headers that carry credentials or describe the connection are dropped: Authorization, cookies and Set-Cookie, API-key headers, Content-Length, Date, Age, Strict-Transport-Security, CORS headers, and those in the project’s Response headers to redact.
  • A redirect to a host the import also holds becomes a path in the project; the user name, password and fragment are removed from every address.

Plain text and HTML are copied as recorded. Redaction matches field and header names, so it does not find personal data or a secret in a path, a name or free text: read what you import.

Importing the same file again creates nothing new for an entry the project already has an identical mock for, or for combined examples whose mock has the same responses, keys and default: the preview shows it as Reuse, and the apply leaves that mock, its status and its tags as they are. A new mock whose name an existing mock already has gets -2 added to it.

A new mock that matches the same requests as an existing one is tagged Same request as another mock. Activate one of them at a time.

If the project changed between the preview and Apply import, such as a mock with the same name created meanwhile, nothing is imported and the page says This import would no longer do what its preview showed. Preview the import again. It reads the plan again for you to review; see Import conflict. If the answer to Apply import never arrives, the page also reads the plan again, and any mock the apply did create shows as Reuse.

The import copies what was recorded. Use Generate mocks with AI to write responses no one recorded, from a description or the commands alone, or to make the data vary. Pasting a HAR, a Postman collection or curl with output into AI generation offers Import exactly as captured instead.

  • A source is at most 8 MiB, with at most 5,000 entries; one import creates at most 500 mocks, whose bodies add up to at most 16 MiB. Export fewer requests, or import a long session in parts.
  • A workspace can preview and apply imports 30 times a minute.
  • Only the method and path are matched, plus one query parameter you choose under Overlapping examples. To answer differently by header or body, add a request matcher to the mock after importing.
  • An import creates mocks only: it never updates or deletes one. A changed recording of an existing mock is a new mock; edit or delete the old one yourself.
  • Binary bodies, compressed bodies that were not decoded, WebSocket messages and Postman v1 collections cannot be imported. An OpenAPI document is imported on the project’s OpenAPI tab instead; see Import an OpenAPI specification.
  • A refusal says why: Import source invalid, Import source unsupported or Import conflict.

Report a problem with this page