Hopp til innhold
DocsSDKAutentisering og API-nøkler

Autentisering og API-nøkler

Oppdatert juli 2026·1 min

Hvert kall autentiseres med en API-nøkkel opprettet i arbeidsområdets innstillinger. Nøkler starter med medal_ og gjelder ett arbeidsområde.

API-nøkler-fanen i personlige innstillinger, med én arbeidsområdenøkkel og Opprett-knappen.API-nøkler-fanen i personlige innstillinger, med én arbeidsområdenøkkel og Opprett-knappen.

new Medal(token, options?)

Pass the API key; options cover baseUrl, timeout, and workspaceId for multi-workspace tokens.

ts
import { Medal } from '@medalsocial/sdk';

const medal = new Medal(process.env.MEDAL_API_KEY as string, {
  timeout: 15_000,
});

Idempotency keys

Idempotency key sent as the Idempotency-Key header. Retries with the same key return the original result instead of repeating the operation. Required by some endpoints for capability-scoped tokens (e.g. helpdesk replies, webhook creation).

ts
await medal.webhooks.create(
  { name: 'CRM sync', url: 'https://example.com/hooks', event_types: ['contact.created'] },
  { idempotencyKey: 'crm-sync-setup-1' }
);

Capability confirmations

Capability confirmation token sent as the X-Capability-Confirmation header. Required alongside idempotencyKey when a token granted a capability-style scope directly (e.g. helpdesk.webhook.manage) executes a confirmable write route. API keys with legacy scopes do not need it.

medal.workspaces.list()

List workspaces accessible to the current API key or OAuth token.

ts
list(): Promise<ApiResponse<Workspace[]>>
Lagt til i v1.0.0