2015-04-10 05:52:02 +00:00
---
2020-01-18 00:18:09 +00:00
layout: api
page_title: HTTP API
description: Vault has an HTTP API that can be used to control every aspect of Vault.
2015-04-10 05:52:02 +00:00
---
# HTTP API
2022-10-27 15:35:17 +00:00
The Vault HTTP API gives you full access to Vault using [REST like HTTP verbs](https://en.wikipedia.org/wiki/Representational_state_transfer).
Every aspect of Vault can be controlled using the APIs. The Vault CLI uses the
HTTP API to access Vault similar to all other consumers.
2015-04-10 05:52:02 +00:00
All API routes are prefixed with `/v1/`.
2018-08-28 19:33:19 +00:00
This documentation is only for the v1 API, which is currently the only version.
2015-04-10 05:52:02 +00:00
2020-01-18 00:18:09 +00:00
~> **Backwards compatibility:** At the current version, Vault does not yet
promise backwards compatibility even with the v1 prefix. We'll remove this
warning when this policy changes. At this point in time the core API (that
is, `sys/` routes) change very infrequently, but various secrets engines/auth
methods/etc. sometimes have minor changes to accommodate new features as
they're developed.
2015-04-10 05:52:02 +00:00
## Transport
2018-08-28 19:33:19 +00:00
The API is expected to be accessed over a TLS connection at all times, with a
valid certificate that is verified by a well-behaved client. It is possible to
disable TLS verification for listeners, however, so API clients should expect
to have to do both depending on user settings.
2015-04-10 05:52:02 +00:00
## Authentication
2018-08-28 19:33:19 +00:00
Once Vault is unsealed, almost every other operation requires a _client token_.
2020-01-18 00:18:09 +00:00
A user may have a client token sent to them. The client token must be sent as
2018-10-17 14:38:15 +00:00
either the `X-Vault-Token` HTTP Header or as `Authorization` HTTP Header using
the `Bearer <token>` scheme.
2015-04-10 05:52:02 +00:00
2022-10-27 15:35:17 +00:00
Otherwise, a client token can be retrieved using an [authentication
2023-01-26 00:12:15 +00:00
engine](/vault/docs/auth).
2015-04-10 05:52:02 +00:00
2018-08-28 19:33:19 +00:00
Each auth method has one or more unauthenticated login endpoints. These
endpoints can be reached without any authentication, and are used for
authentication to Vault itself. These endpoints are specific to each auth
method.
Responses from auth login methods that generate an authentication token are
2022-10-27 15:35:17 +00:00
sent back to the client in JSON. The resulting token should be saved on the
2018-10-17 14:38:15 +00:00
client or passed via the `X-Vault-Token` or `Authorization` header for future requests.
2018-08-28 19:33:19 +00:00
2021-12-14 01:02:39 +00:00
## Parameter restrictions
Several Vault APIs require specifying path parameters. The path parameter cannot end
in periods. Otherwise, Vault will return a 404 unsupported path error.
2018-08-28 19:33:19 +00:00
## Namespaces
2015-04-10 05:52:02 +00:00
2023-01-26 00:12:15 +00:00
When using [Namespaces](/vault/docs/enterprise/namespaces) the final path of the API
2022-10-27 15:35:17 +00:00
request is relative to the `X-Vault-Namespace` header. For instance, if a
request URI is `secret/foo` with the `X-Vault-Namespace` header set as `ns1/ns2/`,
then the resulting request path to Vault will be `ns1/ns2/secret/foo`.
Note that it is semantically equivalent to use the full path rather than the
`X-Vault-Namespace` header, Vault will match the corresponding namespace
based on correlating user input. Similar path results may be achieved if
`X-Vault-Namespace` is set to `ns1/` with the request path of `ns2/secret/foo`
as well, or otherwise if `X-Vault-Namespace` is omitted entirely and instead a
complete path is provided such as: `ns1/ns2/secret/foo`.
2015-04-10 05:52:02 +00:00
2018-08-29 15:26:23 +00:00
For example, the following two commands result in equivalent requests:
2020-05-21 17:18:17 +00:00
```shell-session
2018-08-29 15:26:23 +00:00
$ curl \
-H "X-Vault-Token: f3b09679-3001-009d-2b80-9c306ab81aa6" \
-H "X-Vault-Namespace: ns1/ns2/" \
-X GET \
http://127.0.0.1:8200/v1/secret/foo
```
2020-05-21 17:18:17 +00:00
```shell-session
2018-08-29 15:26:23 +00:00
$ curl \
-H "X-Vault-Token: f3b09679-3001-009d-2b80-9c306ab81aa6" \
-X GET \
http://127.0.0.1:8200/v1/ns1/ns2/secret/foo
```
2018-08-28 19:33:19 +00:00
## API Operations
2016-01-19 23:09:26 +00:00
2022-10-27 15:35:17 +00:00
Typically the request data, body and response data to and from Vault is in JSON.
Vault sets the `Content-Type` header appropriately with its response and does
not require it from the clients request.
2015-05-28 21:28:25 +00:00
2023-01-26 00:12:15 +00:00
The demonstration below uses the [`KVv1` secrets engine](/vault/api-docs/secret/kv/kv-v1), which is a
simple Key/Value store. Please read [the API documentation of KV secret engines](/vault/api-docs/secret/kv)
2022-10-27 15:35:17 +00:00
for details of `KVv1` compared to `KVv2` and how they differ in their URI paths
as well as the features available in version 2 of the KV secrets engine.
2018-08-28 19:33:19 +00:00
2022-10-27 15:35:17 +00:00
For `KVv1`, reading a secret using the HTTP API is done by issuing a GET:
2015-05-28 21:28:25 +00:00
2015-06-01 04:23:44 +00:00
```text
/v1/secret/foo
```
2015-05-28 21:28:25 +00:00
2016-01-19 23:09:26 +00:00
This maps to `secret/foo` where `foo` is the key in the `secret/` mount, which
2017-09-15 13:02:29 +00:00
is mounted by default on a fresh Vault install and is of type `kv`.
2015-05-28 21:28:25 +00:00
Here is an example of reading a secret using cURL:
2020-05-21 17:18:17 +00:00
```shell-session
2015-10-12 16:10:22 +00:00
$ curl \
-H "X-Vault-Token: f3b09679-3001-009d-2b80-9c306ab81aa6" \
-X GET \
http://127.0.0.1:8200/v1/secret/foo
2015-06-01 04:23:44 +00:00
```
2015-05-28 21:28:25 +00:00
2022-10-27 15:35:17 +00:00
A few endpoints consume calls with `GET` query string parameters, but only if
those parameters are not sensitive, especially since some load balancers will
be able log these. Most endpoints that accept `POST` query string parameters
expect those parameters in the request body.
2018-08-28 19:33:19 +00:00
2022-10-27 15:35:17 +00:00
You can list secrets as well. To do this, either issue a `GET` with the query
string parameter `list=true`, or you use the `LIST` HTTP verb. For the `kv` secrets
engine, listing is allowed on directories only, which returns the keys at the
requested path:
2016-01-19 23:09:26 +00:00
2020-05-21 17:18:17 +00:00
```shell-session
2016-01-19 23:09:26 +00:00
$ curl \
-H "X-Vault-Token: f3b09679-3001-009d-2b80-9c306ab81aa6" \
2017-09-13 01:58:17 +00:00
-X LIST \
http://127.0.0.1:8200/v1/secret/
2016-01-19 23:09:26 +00:00
```
2018-08-28 19:33:19 +00:00
The API documentation uses `LIST` as the HTTP verb, but you can still use `GET`
with the `?list=true` query string.
2017-09-13 01:58:17 +00:00
2022-10-27 15:35:17 +00:00
To make an API with specific data in request body, issue a `POST`:
2015-05-28 21:28:25 +00:00
2015-06-01 04:23:44 +00:00
```text
/v1/secret/foo
```
2015-05-28 21:28:25 +00:00
2015-06-01 04:23:44 +00:00
with a JSON body like:
2015-05-28 21:28:25 +00:00
```javascript
{
"value": "bar"
}
```
Here is an example of writing a secret using cURL:
2020-05-21 17:18:17 +00:00
```shell-session
2015-10-12 16:10:22 +00:00
$ curl \
-H "X-Vault-Token: f3b09679-3001-009d-2b80-9c306ab81aa6" \
-H "Content-Type: application/json" \
-X POST \
2022-03-09 22:15:05 +00:00
-d '{"data":{"value":"bar"}}' \
2015-10-12 16:10:22 +00:00
http://127.0.0.1:8200/v1/secret/baz
2015-06-01 04:23:44 +00:00
```
2015-05-28 21:28:25 +00:00
2018-08-28 19:33:19 +00:00
Vault currently considers `PUT` and `POST` to be synonyms. Rather than trust a
2022-10-27 15:35:17 +00:00
client's stated intentions, Vault engines can implement an existence check to
2016-01-19 23:09:26 +00:00
discover whether an operation is actually a create or update operation based on
2018-08-28 19:33:19 +00:00
the data already stored within Vault. This makes permission management via ACLs
more flexible.
2016-01-19 23:09:26 +00:00
2023-01-26 00:12:15 +00:00
A [KVv2 example](/vault/api-docs/secret/kv/kv-v2#sample-request-3) for the engine path of `secret` requires that URI is
2022-10-27 15:35:17 +00:00
appended with ***`data/`*** prior to the secret name (`baz`) such as:
```shell-session
$ curl \
-H "X-Vault-Token: f3b09679-3001-009d-2b80-9c306ab81aa6" \
-H "Content-Type: application/json" \
-X POST \
-d '{"data":{"value":"bar"}}' \
http://127.0.0.1:8200/v1/secret/data/baz
```
2015-06-01 04:23:44 +00:00
For more examples, please look at the Vault API client.
2015-05-28 21:28:25 +00:00
2019-10-17 14:08:59 +00:00
## The `X-Vault-Request` Header
Requests that are sent to a [Vault Agent][agent] that is configured to use the
`require_request_header` option must include the `X-Vault-Request` header
entry, e.g.:
2020-05-21 17:18:17 +00:00
```shell-session
2019-10-17 14:08:59 +00:00
$ curl \
-H "X-Vault-Token: f3b09679-3001-009d-2b80-9c306ab81aa6" \
-H "X-Vault-Request: true" \
-H "Content-Type: application/json" \
-X POST \
-d '{"value":"bar"}' \
http://127.0.0.1:8200/v1/secret/baz
```
The Vault CLI always adds this header to every request, regardless of whether
the request is being sent to a Vault Agent or directly to a Vault Server. In
2020-04-13 16:16:52 +00:00
addition, the Vault SDK always adds this header to every request.
2019-10-17 14:08:59 +00:00
2015-04-10 05:52:02 +00:00
## Help
2022-10-27 15:35:17 +00:00
To retrieve the help for any API within Vault, including mounted engines, auth
2018-08-28 19:33:19 +00:00
methods, etc. then append `?help=1` to any URL. If you have valid permission to
2022-10-27 15:35:17 +00:00
access the path, then the help text will be returned as a markdown-formatted block
in the `help` attribute of the response.
2023-01-26 00:12:15 +00:00
Additionally, with the [OpenAPI generation](/vault/api-docs/system/internal-specs-openapi) in Vault, you will get back a small
2022-10-27 15:35:17 +00:00
OpenAPI document in the `openapi` attribute. This document is relevant for the
path you're looking up and any paths under it - also note paths in the OpenAPI
document are relative to the initial path queried.
2018-12-14 14:12:03 +00:00
Example request:
2020-05-21 17:18:17 +00:00
```shell-session
2018-12-14 14:12:03 +00:00
$ curl \
-H "X-Vault-Token: f3b09679-3001-009d-2b80-9c306ab81aa6" \
http://127.0.0.1:8200/v1/secret?help=1
```
2020-01-18 00:18:09 +00:00
Example response:
2015-04-10 05:52:02 +00:00
2015-04-22 23:47:11 +00:00
```javascript
{
2018-12-14 14:12:03 +00:00
"help": "## DESCRIPTION\n\nThis backend provides a versioned key-value store. The kv backend reads and\nwrites arbitrary secrets to the storage backend. The secrets are\nencrypted/decrypted by Vault: they are never stored unencrypted in the backend\nand the backend never has an opportunity to see the unencrypted value. Each key\ncan have a configured number of versions, and versions can be retrieved based on\ntheir version numbers.\n\n## PATHS\n\nThe following paths are supported by this backend. To view help for\nany of the paths below, use the help command with any route matching\nthe path pattern. Note that depending on the policy of your auth token,\nyou may or may not be able to access certain paths.\n\n ^.*$\n\n\n ^config$\n Configures settings for the KV store\n\n ^data/(?P<path>.*)$\n Write, Read, and Delete data in the Key-Value Store.\n\n ^delete/(?P<path>.*)$\n Marks one or more versions as deleted in the KV store.\n\n ^destroy/(?P<path>.*)$\n Permanently removes one or more versions in the KV store\n\n ^metadata/(?P<path>.*)$\n Configures settings for the KV store\n\n ^undelete/(?P<path>.*)$\n Undeletes one or more versions from the KV store.",
"openapi": {
"openapi": "3.0.2",
"info": {
"title": "HashiCorp Vault API",
"description": "HTTP API that gives you full access to Vault. All API routes are prefixed with `/v1/`.",
"version": "1.0.0",
"license": {
"name": "Mozilla Public License 2.0",
"url": "https://www.mozilla.org/en-US/MPL/2.0"
}
},
"paths": {
"/.*": {},
"/config": {
"description": "Configures settings for the KV store",
"x-vault-create-supported": true,
"get": {
"summary": "Read the backend level settings.",
"tags": [
"secrets"
],
"responses": {
"200": {
"description": "OK"
}
}
},
...[output truncated]...
}
}
2015-04-22 23:47:11 +00:00
}
```
2015-04-10 05:52:02 +00:00
## Error Response
A common JSON structure is always returned to return errors:
2015-04-22 23:47:11 +00:00
```javascript
{
"errors": [
"message",
"another message"
]
}
```
2015-04-10 05:52:02 +00:00
2022-10-27 15:35:17 +00:00
This structure will be returned for any HTTP status greater than or equal to 400.
2015-04-10 05:52:02 +00:00
## HTTP Status Codes
2018-08-28 19:33:19 +00:00
The following HTTP status codes are used throughout the API. Vault tries to
2022-10-27 15:35:17 +00:00
adhere to these whenever possible, but in case it doesn't -- then feel free to
[raise a bug](https://github.com/hashicorp/vault/issues) for our attention!
2015-04-10 05:52:02 +00:00
2020-01-18 00:18:09 +00:00
~> _Note_: Applications should be prepared to accept both `200` and `204` as
2018-10-09 20:54:18 +00:00
success. `204` is simply an indication that there is no response body to parse,
but API endpoints that indicate that they return a `204` may return a `200` if
warnings are generated during the operation.
2015-04-10 05:52:02 +00:00
- `200` - Success with data.
- `204` - Success, no data returned.
2017-05-22 16:37:51 +00:00
- `400` - Invalid request, missing or invalid data.
2018-08-28 19:33:19 +00:00
- `403` - Forbidden, your authentication details are either incorrect, you
don't have access to this feature, or - if CORS is enabled - you made a
cross-origin request from an origin that is not allowed to make such
requests.
- `404` - Invalid path. This can both mean that the path truly doesn't exist or
that you don't have permission to view a specific path. We use 404 in some
cases to avoid state leakage.
2021-09-01 13:51:26 +00:00
- `405` - Unsupported operation. You tried to use a method inappropriate to
the request path, e.g. a POST on an endpoint that only accepts GETs.
- `412` - Precondition failed. Returned on Enterprise when a request can't be
processed yet due to some missing eventually consistent data. Should be retried,
perhaps with a little backoff.
2023-01-26 00:12:15 +00:00
See [Vault Eventual Consistency](/vault/docs/enterprise/consistency).
2018-08-28 19:33:19 +00:00
- `429` - Default return code for health status of standby nodes. This will
likely change in the future.
- `473` - Default return code for health status of performance standby nodes.
- `500` - Internal server error. An internal error has occurred, try again
later. If the error persists, report a bug.
- `502` - A request to Vault required Vault making a request to a third party;
the third party responded with an error of some kind.
2020-01-18 00:18:09 +00:00
- `503` - Vault is down for maintenance or is currently sealed. Try again
2018-08-28 19:33:19 +00:00
later.
2017-02-06 23:24:40 +00:00
## Limits
2018-08-28 19:33:19 +00:00
A maximum request size of 32MB is imposed to prevent a denial of service attack
with arbitrarily large requests; this can be tuned per `listener` block in
Vault's server configuration file.
2019-10-17 14:08:59 +00:00
2023-01-26 00:12:15 +00:00
[agent]: /vault/docs/agent#listener-stanza