Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ aliases:

Use access tokens to sign into the Pulumi Cloud via the CLI or automate your usage of the Pulumi Cloud using the REST API. Learn more about the REST API in the [Pulumi Cloud REST API docs](/docs/reference/cloud-rest-api/).

The token you use for `pulumi login` also authorizes the [`pulumi cloud api`](/docs/iac/cli/cloud-api/) command, which calls any REST API endpoint directly from the CLI without needing to set the `Authorization` header yourself.
The token you use for `pulumi login` also authorizes the [`pulumi api`](/docs/iac/cli/api/) command, which calls any REST API endpoint directly from the CLI without needing to set the `Authorization` header yourself.

Pulumi offers three types of access tokens:

Expand Down
2 changes: 1 addition & 1 deletion content/docs/iac/automation-api/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Automation API requires the Pulumi CLI to be installed and available in your `PA
{{% /notes %}}

{{% notes type="tip" %}}
Automation API drives the Pulumi engine itself, running updates, previews, refreshes, and destroys from a program. If you instead need to read or modify Pulumi Cloud resources (for example, stack metadata, access tokens, or [Insights](/docs/insights/) data) without running a Pulumi program, use [`pulumi cloud api`](/docs/iac/cli/cloud-api/), the CLI command for calling the [Pulumi Cloud REST API](/docs/reference/cloud-rest-api/) directly.
Automation API drives the Pulumi engine itself, running updates, previews, refreshes, and destroys from a program. If you instead need to read or modify Pulumi Cloud resources (for example, stack metadata, access tokens, or [Insights](/docs/insights/) data) without running a Pulumi program, use [`pulumi api`](/docs/iac/cli/api/), the CLI command for calling the [Pulumi Cloud REST API](/docs/reference/cloud-rest-api/) directly.
{{% /notes %}}

## Getting started
Expand Down
2 changes: 1 addition & 1 deletion content/docs/iac/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The most common commands in the CLI that you'll be using are as follows:
* [`pulumi up`](/docs/iac/cli/commands/pulumi_up/): preview and deploy changes to your program and/or infrastructure
* [`pulumi preview`](/docs/iac/cli/commands/pulumi_preview/): preview your changes explicitly before deploying
* [`pulumi destroy`](/docs/iac/cli/commands/pulumi_destroy/): destroy your program and its infrastructure when you're done
* [`pulumi cloud api`](/docs/iac/cli/cloud-api/): call any [Pulumi Cloud REST API](/docs/reference/cloud-rest-api/) endpoint directly from the CLI, with stable exit codes and a JSON error envelope for scripts and agents
* [`pulumi api`](/docs/iac/cli/api/): call any [Pulumi Cloud REST API](/docs/reference/cloud-rest-api/) endpoint directly from the CLI, with stable exit codes and a JSON error envelope for scripts and agents

## Complete Reference

Expand Down
60 changes: 31 additions & 29 deletions content/docs/iac/cli/cloud-api.md → content/docs/iac/cli/api.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
---
title: Calling the Cloud API
title_tag: "Pulumi CLI: Calling the Pulumi Cloud REST API"
meta_desc: Use pulumi cloud api to call any Pulumi Cloud REST API endpoint from the CLI, with stable exit codes and a JSON error envelope for scripts and agents.
meta_desc: Use pulumi api to call any Pulumi Cloud REST API endpoint from the CLI, with stable exit codes and a JSON error envelope for scripts and agents.
h1: Calling the Pulumi Cloud REST API from the CLI
menu:
iac:
parent: iac-cli
identifier: iac-cli-cloud-api
identifier: iac-cli-api
weight: 60
aliases:
- /docs/iac/cli/cloud-api/
meta_image: /images/docs/meta-images/docs-meta.png
---

The [`pulumi cloud api`](/docs/iac/cli/commands/pulumi_cloud_api/) command lets you call any [Pulumi Cloud REST API](/docs/reference/cloud-rest-api/) endpoint directly from the CLI. It runs non-interactively, is safe to script, and reuses the credentials you already use with `pulumi login`, so you don't need to manage a separate token to call the API.
The [`pulumi api`](/docs/iac/cli/commands/pulumi_api/) command lets you call any [Pulumi Cloud REST API](/docs/reference/cloud-rest-api/) endpoint directly from the CLI. It runs non-interactively, is safe to script, and reuses the credentials you already use with `pulumi login`, so you don't need to manage a separate token to call the API.

The command is modeled after [`gh api`](https://cli.github.com/manual/gh_api): you pass a path, an operation ID, or a `METHOD path` row and the CLI handles authentication, headers, path-template substitution, and content negotiation for you.

## Subcommands

`pulumi cloud api` ships in three forms:
`pulumi api` ships in three forms:

* [`pulumi cloud api <path-or-operation-id>`](/docs/iac/cli/commands/pulumi_cloud_api/) issues a single HTTP request against the named endpoint.
* [`pulumi cloud api list`](/docs/iac/cli/commands/pulumi_cloud_api_list/) (alias: `ls`) lists every endpoint exposed by the [Pulumi Cloud OpenAPI spec](/docs/reference/cloud-rest-api/). Output is a TTY-friendly table by default; pass `--format=json` to get a stable, scriptable envelope.
* [`pulumi cloud api describe <path-or-operation-id>`](/docs/iac/cli/commands/pulumi_cloud_api_describe/) prints the parameters, request body, and response schemas for a single operation. Default output is a human-readable text render; pass `--format=markdown` for a piping-friendly markdown document or `--format=json` for the stable JSON envelope.
* [`pulumi api <path-or-operation-id>`](/docs/iac/cli/commands/pulumi_api/) issues a single HTTP request against the named endpoint.
* [`pulumi api list`](/docs/iac/cli/commands/pulumi_api_list/) (alias: `ls`) lists every endpoint exposed by the [Pulumi Cloud OpenAPI spec](/docs/reference/cloud-rest-api/). Output is a TTY-friendly table by default; pass `--format=json` to get a stable, scriptable envelope.
* [`pulumi api describe <path-or-operation-id>`](/docs/iac/cli/commands/pulumi_api_describe/) prints the parameters, request body, and response schemas for a single operation. Default output is a human-readable text render; pass `--format=markdown` for a piping-friendly markdown document or `--format=json` for the stable JSON envelope.

## Authentication

`pulumi cloud api` uses the same access token as the rest of the Pulumi CLI. Anything that authorizes `pulumi login` — a personal, organization, or team [access token](/docs/administration/access-identity/access-tokens/), `PULUMI_ACCESS_TOKEN`, or an OIDC-issued token — also authorizes API calls.
`pulumi api` uses the same access token as the rest of the Pulumi CLI. Anything that authorizes `pulumi login` — a personal, organization, or team [access token](/docs/administration/access-identity/access-tokens/), `PULUMI_ACCESS_TOKEN`, or an OIDC-issued token — also authorizes API calls.

If a request requires authentication and the CLI is not authenticated, `pulumi cloud api` exits with code `3` and an error envelope identifying the auth failure. A `401` or `403` response from the API maps to the same exit code.
If a request requires authentication and the CLI is not authenticated, `pulumi api` exits with code `3` and an error envelope identifying the auth failure. A `401` or `403` response from the API maps to the same exit code.

## Path-template substitution

Most Pulumi Cloud endpoints take an organization, project, or stack as part of the URL — for example, `/api/orgs/{orgName}/members`. `pulumi cloud api` resolves each template variable in the following order:
Most Pulumi Cloud endpoints take an organization, project, or stack as part of the URL — for example, `/api/orgs/{orgName}/members`. `pulumi api` resolves each template variable in the following order:

1. A literal value typed directly into the URL (no template variable to fill).
1. A matching `-F` or `-f` field (consumed for the path and not forwarded as a query or body parameter).
Expand All @@ -40,20 +42,20 @@ Most Pulumi Cloud endpoints take an organization, project, or stack as part of t
When a stack is selected, you can usually call:

```bash
pulumi cloud api ListOrganizationMembers
pulumi api ListOrganizationMembers
```

and the CLI fills `{orgName}` from the selected stack automatically. When no project context is available, supply the values with `-F`:

```bash
pulumi cloud api GetStack -F orgName=acme -F projectName=web -F stackName=prod
pulumi api GetStack -F orgName=acme -F projectName=web -F stackName=prod
```

If a path template and a request body field share a parameter name, the first matching `-F` is consumed for the path. Any subsequent `-F` with the same key is sent in the body, so you can pass `-F` twice to fill both. To keep the body fully separate, use `--body` or `--input` instead.

## Request flags

`pulumi cloud api` accepts a `gh api`-style flag set for shaping the request:
`pulumi api` accepts a `gh api`-style flag set for shaping the request:

| Flag | Purpose |
|---|---|
Expand All @@ -80,7 +82,7 @@ Pass `--refresh-spec` to any subcommand to force a re-fetch.

## Exit codes and error envelope

`pulumi cloud api` uses the standard [Pulumi CLI exit-code mapping](/docs/iac/cli/exit-codes/). The values it can emit are:
`pulumi api` uses the standard [Pulumi CLI exit-code mapping](/docs/iac/cli/exit-codes/). The values it can emit are:

| Exit code | Meaning |
|----------:|---------|
Expand All @@ -100,89 +102,89 @@ On failure, the CLI writes errors to stderr as a single-line JSON envelope with
Inspect the currently authenticated user:

```bash
pulumi cloud api /api/user
pulumi api /api/user
```

Call by URL path with template variables filled from `-F`:

```bash
pulumi cloud api /api/orgs/{orgName}/members -F orgName=acme
pulumi api /api/orgs/{orgName}/members -F orgName=acme
```

Call by operation ID — `orgName` is taken from the current Pulumi project:

```bash
pulumi cloud api ListOrganizationMembers
pulumi api ListOrganizationMembers
```

Pass path variables explicitly when no project context is available:

```bash
pulumi cloud api GetStack -F orgName=acme -F projectName=web -F stackName=prod
pulumi api GetStack -F orgName=acme -F projectName=web -F stackName=prod
```

### Bodies and fields

Create a resource via `POST`; body fields are auto-detected from the operation:

```bash
pulumi cloud api CreateOrgToken -F orgName=acme \
pulumi api CreateOrgToken -F orgName=acme \
-F name=ci-bot -F description="CI deploy token" \
-F admin=false -F expires=0
```

Send a nested JSON body by mixing scalar fields with an inline JSON literal:

```bash
pulumi cloud api CreateStack -F orgName=acme -F projectName=web \
pulumi api CreateStack -F orgName=acme -F projectName=web \
-F stackName=prod -F 'tags={"env":"prod","team":"platform"}'
```

Pass an entire request body inline, or read it from a file or stdin:

```bash
pulumi cloud api UpdateStackTags -F orgName=acme -F projectName=web -F stackName=prod \
pulumi api UpdateStackTags -F orgName=acme -F projectName=web -F stackName=prod \
--body '{"env":"prod","team":"platform"}'

pulumi cloud api UpdateStackTags --input ./tags.json
pulumi api UpdateStackTags --input ./tags.json

cat tags.json | pulumi cloud api UpdateStackTags --input -
cat tags.json | pulumi api UpdateStackTags --input -
```

### Filtering and pagination

Filter the JSON response with `jq`:

```bash
pulumi cloud api /api/user --format=json | jq '.githubLogin'
pulumi api /api/user --format=json | jq '.githubLogin'
```

Walk every page of a paginated endpoint:

```bash
pulumi cloud api ListUserStacks --paginate | jq -r '.stacks[].stackName'
pulumi api ListUserStacks --paginate | jq -r '.stacks[].stackName'
```

### Discovery and dry-run

Browse the API surface and inspect a specific operation:

```bash
pulumi cloud api list --format=json | jq '.operations[] | select(.tag == "Stacks")'
pulumi api list --format=json | jq '.operations[] | select(.tag == "Stacks")'

pulumi cloud api describe CreateOrgToken --format=markdown
pulumi api describe CreateOrgToken --format=markdown
```

Preview the resolved request without sending it:

```bash
pulumi cloud api CreateOrgToken -F orgName=acme \
pulumi api CreateOrgToken -F orgName=acme \
-F name=ci-bot -F description="CI" -F admin=false -F expires=0 --dry-run
```

## See also

* [`pulumi cloud api` command reference](/docs/iac/cli/commands/pulumi_cloud_api/)
* [`pulumi api` command reference](/docs/iac/cli/commands/pulumi_api/)
* [Pulumi Cloud REST API](/docs/reference/cloud-rest-api/)
* [Pulumi Cloud access tokens](/docs/administration/access-identity/access-tokens/)
* [Pulumi CLI exit codes](/docs/iac/cli/exit-codes/)
48 changes: 0 additions & 48 deletions content/docs/iac/cli/commands/pulumi_cloud.md

This file was deleted.

Loading
Loading