# Credentials

## Create Credential

`client.Credentials.New(ctx, body) (*Credential, error)`

**post** `/v5/credentials`

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

### Parameters

- `body CredentialNewParams`

  - `Name param.Field[string]`

    User-friendly name for the credential

  - `Payload param.Field[string]`

    The credential payload to be encrypted

  - `Type param.Field[string]`

    Type of credential: key or json

  - `CredentialMetadata param.Field[map[string, any]]`

    Optional unencrypted credential_metadata

  - `Description param.Field[string]`

    Optional description

### Returns

- `type Credential struct{…}`

  - `ID string`

  - `CreatedAt Time`

  - `CreatedByIdentityType string`

  - `CreatedByUserID string`

  - `CredentialMetadata map[string, any]`

  - `Description string`

  - `Name string`

  - `Type string`

  - `UpdatedAt Time`

  - `Object string`

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/scaleapi/sgp-dev-go"
  "github.com/scaleapi/sgp-dev-go/option"
)

func main() {
  client := sgpdev.NewClient(
    option.WithAPIKey("My API Key"),
    option.WithAccountID("My Account ID"),
  )
  credential, err := client.Credentials.New(context.TODO(), sgpdev.CredentialNewParams{
    Name: "x",
    Payload: "x",
    Type: "x",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", 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.Get(ctx, credentialID) (*Credential, error)`

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

Retrieve a specific credential by its unique identifier.

### Parameters

- `credentialID string`

### Returns

- `type Credential struct{…}`

  - `ID string`

  - `CreatedAt Time`

  - `CreatedByIdentityType string`

  - `CreatedByUserID string`

  - `CredentialMetadata map[string, any]`

  - `Description string`

  - `Name string`

  - `Type string`

  - `UpdatedAt Time`

  - `Object string`

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/scaleapi/sgp-dev-go"
  "github.com/scaleapi/sgp-dev-go/option"
)

func main() {
  client := sgpdev.NewClient(
    option.WithAPIKey("My API Key"),
    option.WithAccountID("My Account ID"),
  )
  credential, err := client.Credentials.Get(context.TODO(), "credential_id")
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", 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.GetByName(ctx, credentialName) (*Credential, error)`

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

Retrieve a specific credential by its name.

### Parameters

- `credentialName string`

### Returns

- `type Credential struct{…}`

  - `ID string`

  - `CreatedAt Time`

  - `CreatedByIdentityType string`

  - `CreatedByUserID string`

  - `CredentialMetadata map[string, any]`

  - `Description string`

  - `Name string`

  - `Type string`

  - `UpdatedAt Time`

  - `Object string`

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/scaleapi/sgp-dev-go"
  "github.com/scaleapi/sgp-dev-go/option"
)

func main() {
  client := sgpdev.NewClient(
    option.WithAPIKey("My API Key"),
    option.WithAccountID("My Account ID"),
  )
  credential, err := client.Credentials.GetByName(context.TODO(), "credential_name")
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", 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(ctx, credentialID) (*CredentialSecret, error)`

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

Retrieve the plaintext payload of a credential by its ID.

### Parameters

- `credentialID string`

### Returns

- `type CredentialSecret struct{…}`

  - `Result string`

  - `Object string`

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/scaleapi/sgp-dev-go"
  "github.com/scaleapi/sgp-dev-go/option"
)

func main() {
  client := sgpdev.NewClient(
    option.WithAPIKey("My API Key"),
    option.WithAccountID("My Account ID"),
  )
  credentialSecret, err := client.Credentials.Decrypt(context.TODO(), "credential_id")
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", credentialSecret.Result)
}
```

#### Response

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

## Get Credential Secret by Name

`client.Credentials.DecryptByName(ctx, credentialName) (*CredentialSecret, error)`

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

Retrieve the plaintext payload of a credential by its name.

### Parameters

- `credentialName string`

### Returns

- `type CredentialSecret struct{…}`

  - `Result string`

  - `Object string`

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/scaleapi/sgp-dev-go"
  "github.com/scaleapi/sgp-dev-go/option"
)

func main() {
  client := sgpdev.NewClient(
    option.WithAPIKey("My API Key"),
    option.WithAccountID("My Account ID"),
  )
  credentialSecret, err := client.Credentials.DecryptByName(context.TODO(), "credential_name")
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", credentialSecret.Result)
}
```

#### Response

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

## List Credentials

`client.Credentials.List(ctx, query) (*CursorPage[Credential], error)`

**get** `/v5/credentials`

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

### Parameters

- `query CredentialListParams`

  - `EndingBefore param.Field[string]`

  - `Limit param.Field[int64]`

  - `Name param.Field[string]`

    Filter credentials by name

  - `SortBy param.Field[string]`

  - `SortOrder param.Field[SortOrder]`

  - `StartingAfter param.Field[string]`

### Returns

- `type Credential struct{…}`

  - `ID string`

  - `CreatedAt Time`

  - `CreatedByIdentityType string`

  - `CreatedByUserID string`

  - `CredentialMetadata map[string, any]`

  - `Description string`

  - `Name string`

  - `Type string`

  - `UpdatedAt Time`

  - `Object string`

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/scaleapi/sgp-dev-go"
  "github.com/scaleapi/sgp-dev-go/option"
)

func main() {
  client := sgpdev.NewClient(
    option.WithAPIKey("My API Key"),
    option.WithAccountID("My Account ID"),
  )
  page, err := client.Credentials.List(context.TODO(), sgpdev.CredentialListParams{

  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
```

#### 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(ctx, credentialID, body) (*Credential, error)`

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

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

### Parameters

- `credentialID string`

- `body CredentialUpdateParams`

  - `CredentialMetadata param.Field[map[string, any]]`

    Optional unencrypted credential_metadata

  - `Description param.Field[string]`

    Optional description

  - `Name param.Field[string]`

    User-friendly name for the credential

  - `Payload param.Field[string]`

    The credential payload to be encrypted

  - `Type param.Field[string]`

    Type of credential: key or json

### Returns

- `type Credential struct{…}`

  - `ID string`

  - `CreatedAt Time`

  - `CreatedByIdentityType string`

  - `CreatedByUserID string`

  - `CredentialMetadata map[string, any]`

  - `Description string`

  - `Name string`

  - `Type string`

  - `UpdatedAt Time`

  - `Object string`

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/scaleapi/sgp-dev-go"
  "github.com/scaleapi/sgp-dev-go/option"
)

func main() {
  client := sgpdev.NewClient(
    option.WithAPIKey("My API Key"),
    option.WithAccountID("My Account ID"),
  )
  credential, err := client.Credentials.Update(
    context.TODO(),
    "credential_id",
    sgpdev.CredentialUpdateParams{

    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", 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(ctx, credentialID) (*CredentialDeleteResponse, error)`

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

Permanently delete a credential and all its associated data.

### Parameters

- `credentialID string`

### Returns

- `type CredentialDeleteResponse struct{…}`

  - `ID string`

  - `Deleted bool`

  - `Object string`

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/scaleapi/sgp-dev-go"
  "github.com/scaleapi/sgp-dev-go/option"
)

func main() {
  client := sgpdev.NewClient(
    option.WithAPIKey("My API Key"),
    option.WithAccountID("My Account ID"),
  )
  credential, err := client.Credentials.Delete(context.TODO(), "credential_id")
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", credential.ID)
}
```

#### Response

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

## Domain Types

### Credential

- `type Credential struct{…}`

  - `ID string`

  - `CreatedAt Time`

  - `CreatedByIdentityType string`

  - `CreatedByUserID string`

  - `CredentialMetadata map[string, any]`

  - `Description string`

  - `Name string`

  - `Type string`

  - `UpdatedAt Time`

  - `Object string`

### Credential Secret

- `type CredentialSecret struct{…}`

  - `Result string`

  - `Object string`
