# Credentials

## Create Credential

`client.credentials.create(CredentialCreateParamsbody, RequestOptionsoptions?): Credential`

**post** `/v5/credentials`

Create a new credential for storing sensitive data like API keys, tokens, or other secrets.

### Parameters

- `body: CredentialCreateParams`

  - `name: string`

    User-friendly name for the credential

  - `payload: string`

    The credential payload to be encrypted

  - `type: string`

    Type of credential: key or json

  - `credential_metadata?: Record<string, unknown>`

    Optional unencrypted credential_metadata

  - `description?: string`

    Optional description

### Returns

- `Credential`

  - `id: string`

  - `created_at: string`

  - `created_by_identity_type: string | null`

  - `created_by_user_id: string | null`

  - `credential_metadata: Record<string, unknown> | null`

  - `description: string | null`

  - `name: string`

  - `type: string`

  - `updated_at: string`

  - `object?: string`

### Example

```typescript
import SGPClient from 'scale-gp';

const client = new SGPClient({
  accountID: 'My Account ID',
  apiKey: process.env['SGP_API_KEY'], // This is the default and can be omitted
});

const credential = await client.credentials.create({
  name: 'x',
  payload: 'x',
  type: 'x',
});

console.log(credential.id);
```

#### Response

```json
{
  "id": "id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "created_by_identity_type": "created_by_identity_type",
  "created_by_user_id": "created_by_user_id",
  "credential_metadata": {
    "foo": "bar"
  },
  "description": "description",
  "name": "name",
  "type": "type",
  "updated_at": "2019-12-27T18:11:19.117Z",
  "object": "object"
}
```

## Get Credential by ID

`client.credentials.retrieve(stringcredentialID, RequestOptionsoptions?): Credential`

**get** `/v5/credentials/{credential_id}`

Retrieve a specific credential by its unique identifier.

### Parameters

- `credentialID: string`

### Returns

- `Credential`

  - `id: string`

  - `created_at: string`

  - `created_by_identity_type: string | null`

  - `created_by_user_id: string | null`

  - `credential_metadata: Record<string, unknown> | null`

  - `description: string | null`

  - `name: string`

  - `type: string`

  - `updated_at: string`

  - `object?: string`

### Example

```typescript
import SGPClient from 'scale-gp';

const client = new SGPClient({
  accountID: 'My Account ID',
  apiKey: process.env['SGP_API_KEY'], // This is the default and can be omitted
});

const credential = await client.credentials.retrieve('credential_id');

console.log(credential.id);
```

#### Response

```json
{
  "id": "id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "created_by_identity_type": "created_by_identity_type",
  "created_by_user_id": "created_by_user_id",
  "credential_metadata": {
    "foo": "bar"
  },
  "description": "description",
  "name": "name",
  "type": "type",
  "updated_at": "2019-12-27T18:11:19.117Z",
  "object": "object"
}
```

## Get Credential by Name

`client.credentials.retrieveByName(stringcredentialName, RequestOptionsoptions?): Credential`

**get** `/v5/credentials/name/{credential_name}`

Retrieve a specific credential by its name.

### Parameters

- `credentialName: string`

### Returns

- `Credential`

  - `id: string`

  - `created_at: string`

  - `created_by_identity_type: string | null`

  - `created_by_user_id: string | null`

  - `credential_metadata: Record<string, unknown> | null`

  - `description: string | null`

  - `name: string`

  - `type: string`

  - `updated_at: string`

  - `object?: string`

### Example

```typescript
import SGPClient from 'scale-gp';

const client = new SGPClient({
  accountID: 'My Account ID',
  apiKey: process.env['SGP_API_KEY'], // This is the default and can be omitted
});

const credential = await client.credentials.retrieveByName('credential_name');

console.log(credential.id);
```

#### Response

```json
{
  "id": "id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "created_by_identity_type": "created_by_identity_type",
  "created_by_user_id": "created_by_user_id",
  "credential_metadata": {
    "foo": "bar"
  },
  "description": "description",
  "name": "name",
  "type": "type",
  "updated_at": "2019-12-27T18:11:19.117Z",
  "object": "object"
}
```

## Get Credential Secret by ID

`client.credentials.decrypt(stringcredentialID, RequestOptionsoptions?): CredentialSecret`

**post** `/v5/credentials/{credential_id}/secret`

Retrieve the plaintext payload of a credential by its ID.

### Parameters

- `credentialID: string`

### Returns

- `CredentialSecret`

  - `result: string`

  - `object?: string`

### Example

```typescript
import SGPClient from 'scale-gp';

const client = new SGPClient({
  accountID: 'My Account ID',
  apiKey: process.env['SGP_API_KEY'], // This is the default and can be omitted
});

const credentialSecret = await client.credentials.decrypt('credential_id');

console.log(credentialSecret.result);
```

#### Response

```json
{
  "result": "result",
  "object": "object"
}
```

## Get Credential Secret by Name

`client.credentials.decryptByName(stringcredentialName, RequestOptionsoptions?): CredentialSecret`

**post** `/v5/credentials/name/{credential_name}/secret`

Retrieve the plaintext payload of a credential by its name.

### Parameters

- `credentialName: string`

### Returns

- `CredentialSecret`

  - `result: string`

  - `object?: string`

### Example

```typescript
import SGPClient from 'scale-gp';

const client = new SGPClient({
  accountID: 'My Account ID',
  apiKey: process.env['SGP_API_KEY'], // This is the default and can be omitted
});

const credentialSecret = await client.credentials.decryptByName('credential_name');

console.log(credentialSecret.result);
```

#### Response

```json
{
  "result": "result",
  "object": "object"
}
```

## List Credentials

`client.credentials.list(CredentialListParamsquery?, RequestOptionsoptions?): CursorPage<Credential>`

**get** `/v5/credentials`

Retrieve a paginated list of all credentials for the current account with optional name filtering.

### Parameters

- `query: CredentialListParams`

  - `ending_before?: string`

  - `limit?: number`

  - `name?: string`

    Filter credentials by name

  - `sort_by?: string`

  - `sort_order?: SortOrder`

    - `"asc"`

    - `"desc"`

  - `starting_after?: string`

### Returns

- `Credential`

  - `id: string`

  - `created_at: string`

  - `created_by_identity_type: string | null`

  - `created_by_user_id: string | null`

  - `credential_metadata: Record<string, unknown> | null`

  - `description: string | null`

  - `name: string`

  - `type: string`

  - `updated_at: string`

  - `object?: string`

### Example

```typescript
import SGPClient from 'scale-gp';

const client = new SGPClient({
  accountID: 'My Account ID',
  apiKey: process.env['SGP_API_KEY'], // This is the default and can be omitted
});

// Automatically fetches more pages as needed.
for await (const credential of client.credentials.list()) {
  console.log(credential.id);
}
```

#### Response

```json
{
  "has_more": true,
  "items": [
    {
      "id": "id",
      "created_at": "2019-12-27T18:11:19.117Z",
      "created_by_identity_type": "created_by_identity_type",
      "created_by_user_id": "created_by_user_id",
      "credential_metadata": {
        "foo": "bar"
      },
      "description": "description",
      "name": "name",
      "type": "type",
      "updated_at": "2019-12-27T18:11:19.117Z",
      "object": "object"
    }
  ],
  "total": 0,
  "limit": 0,
  "object": "list"
}
```

## Update Credential

`client.credentials.update(stringcredentialID, CredentialUpdateParamsbody, RequestOptionsoptions?): Credential`

**patch** `/v5/credentials/{credential_id}`

Update an existing credential's properties including name, description, type, payload, and metadata.

### Parameters

- `credentialID: string`

- `body: CredentialUpdateParams`

  - `credential_metadata?: Record<string, unknown>`

    Optional unencrypted credential_metadata

  - `description?: string`

    Optional description

  - `name?: string`

    User-friendly name for the credential

  - `payload?: string`

    The credential payload to be encrypted

  - `type?: string`

    Type of credential: key or json

### Returns

- `Credential`

  - `id: string`

  - `created_at: string`

  - `created_by_identity_type: string | null`

  - `created_by_user_id: string | null`

  - `credential_metadata: Record<string, unknown> | null`

  - `description: string | null`

  - `name: string`

  - `type: string`

  - `updated_at: string`

  - `object?: string`

### Example

```typescript
import SGPClient from 'scale-gp';

const client = new SGPClient({
  accountID: 'My Account ID',
  apiKey: process.env['SGP_API_KEY'], // This is the default and can be omitted
});

const credential = await client.credentials.update('credential_id');

console.log(credential.id);
```

#### Response

```json
{
  "id": "id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "created_by_identity_type": "created_by_identity_type",
  "created_by_user_id": "created_by_user_id",
  "credential_metadata": {
    "foo": "bar"
  },
  "description": "description",
  "name": "name",
  "type": "type",
  "updated_at": "2019-12-27T18:11:19.117Z",
  "object": "object"
}
```

## Delete Credential

`client.credentials.delete(stringcredentialID, RequestOptionsoptions?): CredentialDeleteResponse`

**delete** `/v5/credentials/{credential_id}`

Permanently delete a credential and all its associated data.

### Parameters

- `credentialID: string`

### Returns

- `CredentialDeleteResponse`

  - `id: string`

  - `deleted: boolean`

  - `object?: string`

### Example

```typescript
import SGPClient from 'scale-gp';

const client = new SGPClient({
  accountID: 'My Account ID',
  apiKey: process.env['SGP_API_KEY'], // This is the default and can be omitted
});

const credential = await client.credentials.delete('credential_id');

console.log(credential.id);
```

#### Response

```json
{
  "id": "id",
  "deleted": true,
  "object": "object"
}
```

## Domain Types

### Credential

- `Credential`

  - `id: string`

  - `created_at: string`

  - `created_by_identity_type: string | null`

  - `created_by_user_id: string | null`

  - `credential_metadata: Record<string, unknown> | null`

  - `description: string | null`

  - `name: string`

  - `type: string`

  - `updated_at: string`

  - `object?: string`

### Credential Secret

- `CredentialSecret`

  - `result: string`

  - `object?: string`

### Credential Delete Response

- `CredentialDeleteResponse`

  - `id: string`

  - `deleted: boolean`

  - `object?: string`
