# Credentials

> Credentials that nodes use to reach external systems.

Source: https://docs.sommatic.ai/en/api/reference/credentials/

## Create a new credential.

`POST /platform-infrastructure/credential/`

Returns the created credential with data provided.

Authentication: Bearer token

### Request body

Credential object to be created.

- `organization_id` (string): Identifier of the organization that this credential is associated with.
- `slug` (string, required): Stable semantic key uniquely identifying this credential within the organization or tenant.
- `name` (string, required): Human-readable name for this credential used in editors, logs and audit trails.
- `type` (PlatformInfrastructureCredentialType, required): Credential type object { id, name, title, color }.
  - `id` (integer, required): Numeric type identifier.
  - `name` (string, required): Machine-readable type name.
  - `title` (string, required): Human-readable label.
  - `color` (string): Optional UI color for the type badge.
- `description` (string): Optional description explaining what this credential is used for and in which contexts.
- `connector_slug` (string): Optional reference to the ConnectorModel this credential is primarily associated with.
- `provider` (PlatformInfrastructureCredentialProvider): Optional provider object { id, name, title, color } identifying the external service.
  - `id` (integer, required): Numeric provider identifier.
  - `name` (string, required): Machine-readable provider name.
  - `title` (string, required): Human-readable label.
  - `color` (string): Optional UI color for the provider badge.
- `secret_backend` (string): Identifier of the secret storage backend used to hold the actual secret material (e.g. "sommatics-vault", "aws-kms").
- `secret_handle` (object): AES-256-GCM encrypted secret material stored as { iv, content, tag }. Encrypted at creation, decrypted only by the resolve endpoint.
- `masked_preview` (string): Optional masked preview of the secret (e.g. last 4 characters) used only for UI display.
- `scopes` (array<string>): Optional list of permission scopes, roles or API grants associated with this credential.
- `allowed_connector_slugs` (array<string>): Optional list of connector keys that are allowed to use this credential for outbound calls.
- `expires_at` (string): Optional expiration timestamp after which this credential must not be used.
- `last_rotated_at` (string): Timestamp of the last successful rotation of the underlying secret material.
- `rotation_policy` (PlatformInfrastructureCredentialRotationPolicy): Optional rotation policy describing how and when this credential should be rotated.
  - `enabled` (boolean): Whether rotation is enabled for this credential.
  - `strategy` (object): Rotation strategy as { id, name, title }.
    - `id` (integer)
    - `name` (string)
    - `title` (string)
  - `interval_days` (integer): Number of days between rotations. Relevant when strategy is "scheduled".
  - `notify_before_days` (integer): Number of days before rotation to send a notification.
- `is_revoked` (boolean): Indicates whether this credential has been revoked and must no longer be used.
- `is_enabled` (boolean): Indicates whether this credential is currently active and eligible for use.
- `is_system` (boolean): Indicates whether this credential is managed by the platform rather than user-created.
- `tags` (array<string>): Optional list of free-form tags used for governance, search and reporting.

### Responses

- `200`: OK.
- `500`: Something was wrong while you make this action.

### Example request

```bash
curl -X POST "https://api.sommatic.ai/platform-infrastructure/credential/" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
       "slug": "<slug>",
       "name": "<name>",
       "type": {
         "id": 0,
         "name": "<name>",
         "title": "<title>"
       }
     }'
```

## Update an existing credential.

`PATCH /platform-infrastructure/credential/`

Updates the data of an existing credential with the data provided.

Authentication: Bearer token

### Request body

Credential object to be updated.

- `organization_id` (string): Identifier of the organization that this credential is associated with.
- `slug` (string, required): Stable semantic key uniquely identifying this credential within the organization or tenant.
- `name` (string, required): Human-readable name for this credential used in editors, logs and audit trails.
- `type` (PlatformInfrastructureCredentialType, required): Credential type object { id, name, title, color }.
  - `id` (integer, required): Numeric type identifier.
  - `name` (string, required): Machine-readable type name.
  - `title` (string, required): Human-readable label.
  - `color` (string): Optional UI color for the type badge.
- `description` (string): Optional description explaining what this credential is used for and in which contexts.
- `connector_slug` (string): Optional reference to the ConnectorModel this credential is primarily associated with.
- `provider` (PlatformInfrastructureCredentialProvider): Optional provider object { id, name, title, color } identifying the external service.
  - `id` (integer, required): Numeric provider identifier.
  - `name` (string, required): Machine-readable provider name.
  - `title` (string, required): Human-readable label.
  - `color` (string): Optional UI color for the provider badge.
- `secret_backend` (string): Identifier of the secret storage backend used to hold the actual secret material (e.g. "sommatics-vault", "aws-kms").
- `secret_handle` (object): AES-256-GCM encrypted secret material stored as { iv, content, tag }. Encrypted at creation, decrypted only by the resolve endpoint.
- `masked_preview` (string): Optional masked preview of the secret (e.g. last 4 characters) used only for UI display.
- `scopes` (array<string>): Optional list of permission scopes, roles or API grants associated with this credential.
- `allowed_connector_slugs` (array<string>): Optional list of connector keys that are allowed to use this credential for outbound calls.
- `expires_at` (string): Optional expiration timestamp after which this credential must not be used.
- `last_rotated_at` (string): Timestamp of the last successful rotation of the underlying secret material.
- `rotation_policy` (PlatformInfrastructureCredentialRotationPolicy): Optional rotation policy describing how and when this credential should be rotated.
  - `enabled` (boolean): Whether rotation is enabled for this credential.
  - `strategy` (object): Rotation strategy as { id, name, title }.
    - `id` (integer)
    - `name` (string)
    - `title` (string)
  - `interval_days` (integer): Number of days between rotations. Relevant when strategy is "scheduled".
  - `notify_before_days` (integer): Number of days before rotation to send a notification.
- `is_revoked` (boolean): Indicates whether this credential has been revoked and must no longer be used.
- `is_enabled` (boolean): Indicates whether this credential is currently active and eligible for use.
- `is_system` (boolean): Indicates whether this credential is managed by the platform rather than user-created.
- `tags` (array<string>): Optional list of free-form tags used for governance, search and reporting.

### Responses

- `200`: OK.
- `500`: Something was wrong while you make this action.

### Example request

```bash
curl -X PATCH "https://api.sommatic.ai/platform-infrastructure/credential/" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
       "slug": "<slug>",
       "name": "<name>",
       "type": {
         "id": 0,
         "name": "<name>",
         "title": "<title>"
       }
     }'
```

## Delete a credential by its id.

`DELETE /platform-infrastructure/credential/`

Deletes a credential based on the provided ID.

Authentication: Bearer token

### Request body

ID of the credential to delete

- `id` (string)

### Responses

- `200`: OK.
- `500`: Something went wrong while performing this action.

### Example request

```bash
curl -X DELETE "https://api.sommatic.ai/platform-infrastructure/credential/" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
       "id": "<id>"
     }'
```

## Get a credential by query selector.

`GET /platform-infrastructure/credential/{queryselector}`

Returns the credential information that matches the query selector and search specified in the route.

Authentication: Bearer token

### Parameters

- `queryselector` (path, enum, required): Is the filter available for this query Allowed values: `id`, `organization-id`, `all`, `status`.
- `search` (query, string): Keyword to search for entities.
- `include_status` (query, string): Optional status parameter to include credentials of a specific status.
- `exclude_status` (query, string): Optional status parameter to exclude credentials of a specific status.
- `page` (query, integer): Page number, starting at 1 (default 1).
- `pageSize` (query, integer): Records per page (default 25).

### Responses

- `200`: OK.
- `500`: Something was wrong while you make this action.

### Example request

```bash
curl -X GET "https://api.sommatic.ai/platform-infrastructure/credential/<queryselector>" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN"
```
