الانتقال إلى المحتوى
DocsSDKالمصادقة ومفاتيح API

المصادقة ومفاتيح API

تم التحديث يوليو 2026·1 min

كل طلب يُصادَق بمفتاح API يُنشأ من إعدادات مساحة العمل. تبدأ المفاتيح بـ medal_ وتخص مساحة عمل واحدة.

تبويب مفاتيح API في الإعدادات الشخصية، مع مفتاح واحد وزر إنشاء مفتاح.تبويب مفاتيح API في الإعدادات الشخصية، مع مفتاح واحد وزر إنشاء مفتاح.

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[]>>
أُضيف في v1.0.0