Netraptor

How to create a Postman collection from your browser's requests

Updated · 6 min read

To build a Postman collection from a website's requests, copy each API call from the Chrome DevTools Network panel with Copy as cURL, then paste it into Postman's Import dialog and save it into a collection. Once the requests are in, replace hard-coded hosts and tokens with variables and export the collection as JSON to share it.

Steps

  1. 1

    Capture the API calls in Chrome

    Open DevTools (F12, or Cmd+Option+I on macOS), go to the Network panel and click Fetch/XHR. Use the feature in the web app so its API requests show up in the list.

  2. 2

    Copy a request as cURL

    Right-click the request you want and choose Copy > Copy as cURL. Chrome copies the method, URL, headers, cookies and body as one command.

  3. 3

    Open Postman's Import dialog

    In your Postman workspace, click Use resources or import and select the Import tab.

  4. 4

    Import the command into a collection

    Paste the cURL command into the text box at the top, enter a request name and a new or existing collection name, then click Import Into Collection.

  5. 5

    Repeat and clean up

    Repeat for each endpoint you need. Then move the base URL into a {{baseUrl}} collection variable and set auth once on the collection instead of in every request.

  6. 6

    Export the collection

    Click Collections in the sidebar, open View more actions next to your collection, select More > Export collection, then click Export JSON.

What is a Postman collection?

A Postman collection is a saved, ordered group of API requests, organized into folders, that you can run, share and version. Besides the requests themselves, a collection can hold variables, auth settings and pre-request or test scripts that apply to everything inside it.

On disk, a collection is a JSON file that follows the Postman Collection v2.1 schema. This is the format tools mean when they say they import or export "a Postman collection". A minimal one looks like this:

{
  "info": {
    "name": "Example app API",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [{ "key": "baseUrl", "value": "https://app.example.com" }],
  "auth": {
    "type": "bearer",
    "bearer": [{ "key": "token", "value": "{{token}}", "type": "string" }]
  },
  "item": [
    {
      "name": "Orders",
      "item": [
        {
          "name": "List orders",
          "request": { "method": "GET", "url": "{{baseUrl}}/api/orders?page=1" }
        }
      ]
    }
  ]
}

Requests without their own auth inherit it from the parent folder or collection, which is why setting it once at the top saves a lot of edits.

How to use Copy as cURL in Chrome

Copy as cURL is the most reliable way to move a single browser request into Postman, because it keeps everything the browser actually sent. In the Network panel, right-click a request and open the Copy submenu. The options that matter here:

  • Copy as cURL: one request as a curl command, ready to paste into Postman or a terminal.
  • Copy all as cURL: every request currently listed, as a chain of curl commands. Useful for a script, but import into Postman one command at a time to keep request names sensible.
  • Copy as fetch: the same request as JavaScript, if you want to replay it from the console instead.

See the Chrome Network features reference for the full list.

How to import a collection in Postman

The same Import dialog handles cURL and full collection files. Click Use resources or import, select Import, then pick a file or folder, drag it into the window, or paste raw text or a URL. You can also drag files straight into the Postman window. When the import finishes, an Import Complete message appears and the collection shows in the left sidebar.

According to Postman's import documentation, the dialog accepts:

  • Postman collections, environments, globals and data dumps.
  • cURL commands, imported as single requests.
  • OpenAPI specifications, as a collection or as a specification with a collection. AsyncAPI, protobuf, GraphQL and Smithy import as specifications.
  • Data from SoapUI, Hoppscotch, Insomnia and Thunder Client, and files from a Git repository.

Collections in the old v1 format are rejected. Convert them with the Postman Collection Transformer first. If you have a whole API described in OpenAPI, importing the spec is faster than pasting requests one by one. See how to generate an OpenAPI spec from traffic.

How to export a collection from Postman

Click Collections in the sidebar, open View more actions next to the collection, choose More > Export collection, and click Export JSON. Postman downloads the collection as a JSON file that you can import into any other Postman instance, commit to a repository or run in CI. The steps are in Postman's export documentation.

Environments export separately. Collection variables travel with the collection, but secrets you keep in an environment do not, which is usually what you want when sharing.

How to copy a request as cURL from Postman

To go the other way and get a curl command out of Postman, open the request, click Code in the right sidebar, select cURL from the dropdown and click Copy. The code settings icon next to the dropdown controls options such as indentation. This is handy for adding a reproducible command to a bug report.

Clean up the collection before you share or run it

Requests copied from a browser carry a lot of noise. A short cleanup pass makes the collection reusable:

  • Replace the host in every URL with {{baseUrl}} so the same collection works against local, staging and production.
  • Delete Cookie and Authorization headers from individual requests and set auth on the collection, using a {{token}} variable.
  • Remove browser-only headers such as sec-ch-ua, sec-fetch-*, user-agent and referer unless the server needs them.
  • Replace IDs in paths with variables, for example {{baseUrl}}/api/users/{{userId}}.
  • Group requests into folders by feature or page.

To run every request in order, open the collection and use the Collection Runner. From a terminal or CI, run the exported file with the Postman CLI or Newman, for example npx newman run example-app.postman_collection.json.

Faster: export a Postman collection with Netraptor

Copying requests one at a time works for five endpoints. For a whole app it is slow and easy to miss calls. Netraptor records the API traffic and writes the collection for you.

  • Turn on Keep history for this site in the Netraptor popup and use the app. It records fetch and XHR calls for that domain and its subdomains across page loads, without DevTools open.
  • Optionally run Crawl this site to visit the app's same-origin links in your logged-in tab. It skips logout and delete-looking links. Free crawls up to 25 pages, Pro up to 1000.
  • Open the Netraptor panel in DevTools and check API Map to see the endpoints it found, with IDs parameterized as /users/{id}.
  • On the Export tab, export a Postman Collection v2.1, grouped by page. Strip auth headers and cookies is on by default. Import the file through Postman's Import dialog.

Postman, HAR and curl exports are on the Free plan. OpenAPI 3.1, Bruno and Insomnia exports are part of Pro, a one-time $29.99 licence. Recording and exports stay in your browser, with no account.

Frequently asked questions

What is a Postman collection used for?
A collection groups related API requests so you can rerun them, share them with your team, document an API and run automated tests with the Collection Runner or from CI.
What file format is a Postman collection?
A JSON file that follows the Postman Collection schema, currently v2.1. Postman no longer imports the old v1 format.
Can I import a cURL command into Postman?
Yes. Paste it into the text box on the Import tab, or directly into a request's URL field, and Postman fills in the method, URL, headers and body.
How do I share a Postman collection without my token?
Remove Authorization and Cookie headers from requests, put the token in an environment variable instead, and export only the collection.
Can I export a collection from Postman as cURL?
Postman generates cURL per request through the Code panel in the right sidebar. For a whole collection you export JSON and convert it, or export curl commands from the tool that captured the traffic.