Skip to content

Create Credential

client.credentials.create(CredentialCreateParams { name, payload, type, 2 more } body, RequestOptionsoptions?): Credential { id, created_at, created_by_identity_type, 7 more }
POST/v5/credentials

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

ParametersExpand Collapse
body: CredentialCreateParams { name, payload, type, 2 more }
name: string

User-friendly name for the credential

minLength1
payload: string

The credential payload to be encrypted

minLength1
formatpassword
type: string

Type of credential: key or json

minLength1
credential_metadata?: Record<string, unknown>

Optional unencrypted credential_metadata

description?: string

Optional description

ReturnsExpand Collapse
Credential { id, created_at, created_by_identity_type, 7 more }
id: string
created_at: string
formatdate-time
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
formatdate-time
object?: string

Create Credential

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