# api (https://hotcodepush.com/docs/cli/commands/api)

How hotcodepush api sends one authenticated request to a path of the REST API, fills the app and organization ids and prints the answer.

Send one request to the [REST API](https://hotcodepush.com/docs/api) with your stored login or `HOTCODEPUSH_TOKEN`, and print the response body.
Use it for an endpoint, a filter or a format that no other command covers.

`<path>` is a path as the [Swagger reference](https://api.hotcodepush.com/docs) writes it, such as `/v1/apps/{appId}/channels`, with its query string.
The CLI fills `{appId}` from `hotcodepush.json` or `--app`, and `{organizationId}` from `--organization` or the only organization you belong to.
Write any other id into the path yourself.

A JSON answer prints formatted, as every `--json` output does.
Any other answer, such as the CSV of `?format=csv`, prints as the bytes received, and an empty answer prints nothing.

> **The command asks no confirmation**
>
> A `DELETE`, `PATCH`, `POST` or `PUT` runs at once, without the question the matching command asks. The API still allows only what your login or token may do.

| Option | Type | Description |
|---|---|---|
| `--body-path <file>` | string | The JSON file to send as the request body, or - for stdin. |
| `--json` | boolean | Print an error as JSON on stdout. The response body prints the same with and without it. |
| `--method <method>` | DELETE \| GET \| PATCH \| POST \| PUT | The HTTP method, DELETE, GET, PATCH, POST or PUT. Defaults to GET, or to POST when --body-path is passed. |

```sh
hotcodepush api '/v1/apps/{appId}/channels?limit=100'
hotcodepush api '/v1/apps/{appId}/channels' --body-path channel.json
```

A body can come from stdin, and `?relations=` embeds a linked row that a command leaves out:

```sh
echo '{"name":"beta"}' | hotcodepush api '/v1/apps/{appId}/channels' --body-path -
hotcodepush api '/v1/apps/{appId}/releases/<releaseId>?relations=channel'
```

The leading slash of the path may be left out, which Git Bash on Windows needs, since it rewrites an argument that starts with one.
A `GET`, `DELETE` or `PUT` is retried as the [Node.js client](https://hotcodepush.com/docs/api/node#retries-and-idempotency) retries it.

The CLI refuses a placeholder it cannot fill, a body that is no JSON and a body on a `GET` as [`invalid_parameter`](https://hotcodepush.com/docs/cli/errors#invalid_parameter).
An API error passes through with its own code and message.
