# Set a secret

> Add a secret, or replace it.

`PUT /v1/tenants/{tenant}/secrets/{name}`

```bash curl
curl -X PUT "https://api.shako.dev/v1/tenants/acme/secrets/GH_TOKEN" \
  -H "Authorization: Bearer $SHAKO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"value":"ghp_...","hosts":["github.com","api.github.com"]}'
```

```python Python
import os

import requests

response = requests.put(
    "https://api.shako.dev/v1/tenants/acme/secrets/GH_TOKEN",
    headers={"Authorization": f"Bearer {os.environ['SHAKO_API_KEY']}"},
    json={
        "value": "ghp_...",
        "hosts": ["github.com", "api.github.com"],
    },
)
response.raise_for_status()
print(response.json())
```

```javascript JavaScript
const response = await fetch("https://api.shako.dev/v1/tenants/acme/secrets/GH_TOKEN", {
  method: "PUT",
  headers: { Authorization: `Bearer ${process.env.SHAKO_API_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    "value": "ghp_...",
    "hosts": [
      "github.com",
      "api.github.com"
    ]
  }),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
```

```json 200 (excerpt)
{
  "name": "GH_TOKEN",
  "hosts": [
    "github.com",
    "api.github.com"
  ],
  "hint": "x9Qz",
  "updated": 1793491200
}
```

Authenticate with `Authorization: Bearer <API key>` on `https://api.shako.dev`. Role: contributor or owner.

## Path parameters

**tenant** `string` *required*

The tenant's name, from GET /v1/tenants.

**name** `string` *required*

The secret's name. It is also the name of the variable in the VMs: A-Z, 0-9 and _, not first a digit, at most 64 characters.

## Request body

**value** `string` *required*

The value, at most 4096 characters. It never goes into a VM.

**hosts** `string[]` *required*

The hosts that get the value, at most 10. Only the requests to these hosts get it, for example ["github.com", "api.github.com"].

## Response

200 with [the secret object](https://shako.dev/api/objects/secret-view.md).

## Behavior

Only the headers of the requests to the hosts get the value.

The errors: https://shako.dev/api/errors.md. All the endpoints of Secrets: https://shako.dev/api/secrets.md.
