Skip to content

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.

ParametersExpand Collapse
body CredentialNewParams
Name param.Field[string]

User-friendly name for the credential

minLength1
Payload param.Field[string]

The credential payload to be encrypted

minLength1
formatpassword
Type param.Field[string]

Type of credential: key or json

minLength1
CredentialMetadata param.Field[map[string, any]]Optional

Optional unencrypted credential_metadata

Description param.Field[string]Optional

Optional description

ReturnsExpand Collapse
type Credential struct{…}
ID string
CreatedAt Time
formatdate-time
CreatedByIdentityType string
CreatedByUserID string
CredentialMetadata map[string, any]
Description string
Name string
Type string
UpdatedAt Time
formatdate-time
Object stringOptional

Create Credential

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)
}
{
  "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"
}
Returns Examples
{
  "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"
}