---
title: "Store a connection credential"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.cloudraker.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Store a connection credential

Path: CloudRaker Workspace API › Connections

`POST /spaces/{spaceId}/connections/{connectionId}/credentials`

Stores a secret (an API key, a bot token) for this connection in the encrypted secret store. WRITE-ONLY: the value is never persisted by us, never echoed by any route, and never reaches the agent or its code sandbox — it is read only at call time, to authenticate the outbound request. The response carries the opaque reference. Re-posting the same `purpose` rotates the secret in place (the reference does not change). Authorization: `space:contribute`.

## Authentication

- `bearerAuth`, http, header `Authorization`

## Path parameters

- `spaceId` (`putConnectionCredential.path.spaceId`; string, required)
- `connectionId` (`putConnectionCredential.path.connectionId`; string, required)

## Request body

_Required._

- `purpose` (`putConnectionCredential.purpose`; string, required)
  - minLength 1; maxLength 64; example `"apiKey"`
- `value` (`putConnectionCredential.value`; string, required)
  - minLength 1
- `expiresAt` (`putConnectionCredential.expiresAt`; string, optional)

## Example request

```json
{
  "purpose": "apiKey",
  "value": "string",
  "expiresAt": "string"
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://api.cloudraker.com/spaces/<spaceId>/connections/<connectionId>/credentials' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "purpose": "apiKey",
  "value": "string",
  "expiresAt": "string"
}
'
```

### TypeScript

```typescript
const url = 'https://api.cloudraker.com/spaces/<spaceId>/connections/<connectionId>/credentials';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({purpose: 'apiKey', value: 'string', expiresAt: 'string'})
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.cloudraker.com/spaces/<spaceId>/connections/<connectionId>/credentials"

payload = {
    "purpose": "apiKey",
    "value": "string",
    "expiresAt": "string"
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

The stored credential reference.

#### Example

```json
{
  "data": {
    "credentialRef": "string",
    "purpose": "string"
  }
}
```

- `data` (`putConnectionCredential.response.200.data`; object, required)
  - `credentialRef` (`putConnectionCredential.response.200.data.credentialRef`; string, required)
  - `purpose` (`putConnectionCredential.response.200.data.purpose`; string, required)


Source: https://docs.cloudraker.com/workspace/api/connections/put-connection-credential/index.md
