Skip to content

feat: allow resolving Postman API resources against a self-hosted deployment - #3381

Open
kavyansh-pancholi wants to merge 1 commit into
developfrom
feat/configurable-postman-api-base-url
Open

feat: allow resolving Postman API resources against a self-hosted deployment#3381
kavyansh-pancholi wants to merge 1 commit into
developfrom
feat/configurable-postman-api-base-url

Conversation

@kavyansh-pancholi

Copy link
Copy Markdown

Problem

Newman hardcodes the Postman API host in lib/util.js, in two separate places:

POSTMAN_API_HOSTS = { 'api.postman.com': true, 'api.getpostman.com': true },
POSTMAN_API_URL   = 'https://api.postman.com',

This makes --postman-api-key unusable against a self-hosted (Postman Private Cloud) deployment, in two different ways:

invocation today
newman run <uid> --postman-api-key <key> uid is expanded to https://api.postman.com/... — silently targets public SaaS
newman run https://api.self-hosted…/collections/<uid> --postman-api-key <key> host is not on the allowlist, so X-Api-Key is never attached

Both surface the same Invalid API Key error, and nothing indicates the flag was ignored.

The only method that works today is embedding ?apikey= in the URL — which places the credential in argv, shell history, and every access log between the client and the server. For CI that is materially worse than a header.

Change

A configurable base URL, resolved as:

postmanApiBaseUrl run option → POSTMAN_API_BASE_URL env var → the public Postman API

The environment variable name matches the one the Postman CLI already uses, so a self-hosted user configures one variable for both tools.

  • bin/newman.js — new --postman-api-base-url <url> option
  • lib/util.jsresolveApiUrl() and isPostmanApiHost() helpers; fetchJson uses them
  • lib/config/index.js — thread the new key through the common-options pick
  • Covers both collections and environments uid resolution (POSTMAN_API_PATH_MAP)

Default behaviour is unchanged when no override is set.

Security note

The host allowlist exists to stop the API key being sent to an arbitrary host named on the command line. That property is preserved: the allowlist is widened only to the single host the user explicitly configured, never to any URL passed in. There is an explicit test for this:

should NOT send the API key to a host that is not configured

Usage

$ newman run $collectionUid --environment $environmentUid \
    --postman-api-key $apiKey \
    --postman-api-base-url https://api.postman.example.com

or

$ export POSTMAN_API_BASE_URL=https://api.postman.example.com
$ newman run $collectionUid --postman-api-key $apiKey

Tests

8 new cases in test/library/postman-api-key.test.js, following the existing nock/sinon pattern: uid resolution for collections and environments, env-var support, option-over-env precedence, trailing-slash tolerance, header attached for the configured host, header not attached for an unrelated host, and unchanged default behaviour.

16 passing   (8 existing + 8 new)

test-lint clean. test-unit 128 passing, test-library 77 passing. test-system has one pre-existing failure (npm publish > should not publish unnecessary files) that also fails on a clean develop checkout and is unrelated to this change.

Also verified end to end against a real self-hosted deployment — bare uid via env var, bare uid via flag, and a full self-hosted URL with --postman-api-key all fetch and execute; with no override set the run still goes to the public API and fails as before.

Docs

README gains a Self-hosted Postman deployments subsection, plus a note that the uid form sends the key as a header rather than a query parameter.

…loyment

Newman hardcoded the Postman API host in two places, which made it unusable
against self-hosted (Postman Private Cloud) deployments:

- a bare resource `uid` was always expanded to `https://api.postman.com`, so
  `--postman-api-key` silently targeted public SaaS;
- the `X-Api-Key` header was only attached when the URL host was on a fixed
  allowlist, so passing a self-hosted URL caused the key to be dropped and the
  fetch to fail with `Invalid API Key`.

The only working alternative was embedding `?apikey=` in the URL, which puts
the credential in argv, shell history and every access log along the path.

Adds a configurable base URL, resolved as: `postmanApiBaseUrl` run option >
`POSTMAN_API_BASE_URL` environment variable > the public Postman API. The
variable name matches the one already used by the Postman CLI.

The host allowlist is widened only to the host the user explicitly configured,
never to arbitrary URLs — it exists to stop the API key being sent to a
third-party host named on the command line, and that property is preserved.

Covers both `collections` and `environments` uid resolution.
@codecov-commenter

codecov-commenter commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.27%. Comparing base (942d139) to head (cca9b3b).

Files with missing lines Patch % Lines
lib/util.js 91.66% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (92.30%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project status has failed because the head coverage (52.15%) is below the target coverage (65.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3381      +/-   ##
===========================================
+ Coverage    81.85%   82.27%   +0.41%     
===========================================
  Files           21       21              
  Lines         1152     1162      +10     
  Branches       352      357       +5     
===========================================
+ Hits           943      956      +13     
+ Misses         114      111       -3     
  Partials        95       95              
Flag Coverage Δ
cli 71.51% <46.15%> (+0.33%) ⬆️
integration 35.37% <38.46%> (-0.05%) ⬇️
library 52.15% <92.30%> (+0.32%) ⬆️
unit 65.74% <38.46%> (-0.40%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants