Postman CLI request commands (postman request)

View as Markdown

This topic covers request testing commands for the Postman CLI.

postman request

Use the postman request command to test and debug HTTP requests from the command line with the Postman CLI. Use many of Postman’s features for sending requests, including authentication, environment variables, test assertions, and more. The command accepts the request’s method (GET, POST, PUT, DELETE, PATCH, HEAD, or OPTIONS) as the first argument, defaulting to GET if a method isn’t provided. The command accepts the target URL as the second argument.

In Postman, you can also convert an API request into a Postman CLI code snippet. Copy the generated code snippet, add options to help you test your request, then send the request with the Postman CLI.

The command reports usage analytics to Postman by default. To turn this off, pass --report-events=false.

Usage

postman request [method] <url> [options]
[method]
Defaults to GET

The HTTP method (GET, POST, PUT, DELETE, PATCH, HEAD, or OPTIONS).

<url>

The target URL for the request.

Options

--auth-[type]-[parameter] [value]

Specifies the authentication type and parameters. Supports the basic, bearer, digest, oauth1, oauth2, hawk, aws, ntlm, and apikey authentication types.

For example: --auth-basic-username user --auth-basic-password pass or --auth-apikey-key "X-API-Key" --auth-apikey-value "abc123" --auth-apikey-in header

--body [body], -d

Specifies request body content. Supports inline string or @filepath syntax for files. For example: --body '{"name": "John"}' or --body @data.json

--cookie-jar [path]

Specifies the file path for a JSON cookie jar to load cookies from before the request runs. This uses the tough-cookie library to deserialize the file.

--dataset [path-or-dir]

Loads one or more local .dataset.yaml files, or directories of them, for the request to use. Pass --dataset more than once to load multiple datasets.

--debug

Shows detailed information in debug mode, including retry attempts, redirects, and timing breakdowns.

--environment [UUID] or [file-path], -e

Specifies an environment file path or UUID. Resolves variables in the URL, headers, and body.

--export-cookie-jar [path]

Specifies the path where the Postman CLI outputs the final cookie jar file after the request completes. This uses the tough-cookie library to serialize the file.

--form [field], -f

Specifies multipart/form-data in key=value format. Use @filepath syntax for files. Can be used multiple times.

For example: -f "name=John" or -f "avatar=@photo.jpg"

--header [header], -H

Specifies a header in key-value format. Can be used multiple times.

For example: -H Content-Type:application/json

--insecure, -k

Turns off SSL verification checks and enables self-signed SSL certificates.

--output [path], -o

Saves the complete response to a JSON file, including status, headers, body, and more. Use for debugging or further processing.

--report-events

Usage analytics are reported to Postman by default, whether or not you pass --report-events. To turn reporting off, pass --report-events=false. You can also use --no-report-events.

--response-only

Suppresses all output except the response body. This is useful for piping to other commands.

--redirects-follow-method

Preserves the original HTTP method when 3xx redirect responses. Redirects are followed with the GET method by default.

--redirects-ignore

Prevents the Postman CLI from automatically following 3xx redirect responses. Redirects are followed by default.

--redirects-max [number]

Specifies the maximum number of 3xx redirect responses to follow. There is no limit by default. Useful for preventing redirect loops.

--redirects-remove-referrer

Removes the Referer header when following 3xx redirect responses. The Referer header is sent with redirects by default.

--retry [number]
Defaults to 0

Specifies the number of retry attempts for failed requests, like a 400 Bad Request code. Useful for unreliable endpoints or rate limited APIs.

--retry-delay [number]
Defaults to 1000

Specifies the time (in milliseconds) to wait to retry the request.

--script-post-request [script]

Adds JavaScript that runs after the request runs. Supports inline JavaScript or @filepath syntax for files. Learn more about writing post-response scripts.

For example: --script-post-request "console.log(pm.response.json());"

--script-pre-request [script]

Adds JavaScript that runs before the request runs. Supports inline JavaScript or @filepath syntax for files. Learn more about writing pre-request scripts.

For example: --script-pre-request "pm.environment.set('timestamp', Date.now());"

--ssl-client-cert <path>

Specifies the path to a client certificate (PEM).

--ssl-client-cert-list <path>

Specifies the path to a client certificates configuration (JSON).

--ssl-client-key <path>

Specifies the path to a client certificate private key.

--ssl-client-passphrase <passphrase>

Specifies the client certificate passphrase (for a protected key).

--ssl-extra-ca-certs <path>

Specifies more trusted CA certificates (PEM).

--timeout [number]
Defaults to 300000

Specifies the time (in milliseconds) to wait for the request to complete.

--verbose

Shows detailed information for the request and response, including headers, body, and metadata.

Examples

postman request GET https://api.example.com/users
postman request POST https://api.example.com/users \
--body '{"name": "John", "email": "john@example.com"}'
postman request https://api.example.com/data \
--auth-apikey-key "apikey" \
--auth-apikey-value "abc123xyz" \
--auth-apikey-in query

Exit codes

The postman request command sets a process exit code so scripts and CI/CD pipelines can act on the result:

  • 0 — the response status code is 2xx or 3xx and all tests passed.
  • 1 — the response status code isn’t 2xx or 3xx, and no tests failed.
  • N — the number of failed tests, when one or more tests fail (for example, 3 when three tests fail). This takes precedence over 1. If the response status also isn’t 2xx or 3xx, you get the test count, not 1.