Skip to content

Scopes & Permissions

The Scopes resource lets you query API key permissions and understand the full permission model.

Get Allowed Scopes

Returns the scopes/permissions granted to the currently authenticated API key.

Endpoint: GET /api/sdk/v1/scopes-allowed

Response (AllowedScopesResponse)

FieldTypeDescription
keyPrefixstringThe API key prefix (e.g., 'sk_live')
namestringHuman-readable name of the API key
scopesstring[]Array of granted scope strings
const { keyPrefix, name, scopes } = await sdk.scopes.getAllowed();
console.log(`API Key: ${name} (${keyPrefix})`);
console.log('Granted scopes:');
scopes.forEach(s => console.log(` - ${s}`));
// Check specific permission
if (scopes.includes('documents:signed:read')) {
console.log('Can read signed documents');
}

Get All Available Scopes

Returns every scope available in the Sonar system, organized hierarchically by category and type.

Endpoint: GET /api/sdk/v1/scopes-allowed/all

Response Hierarchy

ScopeCategory[]
└── id: string (e.g., "documents")
└── label: string (e.g., "Documents")
└── types: ScopeType[]
└── id: string (e.g., "signed")
└── label: string (e.g., "Signed")
└── scopes: ScopeEntry[]
└── value: string (e.g., "documents:signed:read")
└── label: string (e.g., "Read")
const categories = await sdk.scopes.getAll();
for (const category of categories) {
console.log(`\n${category.label} (${category.id}):`);
for (const type of category.types) {
console.log(` ${type.label}:`);
for (const scope of type.scopes) {
console.log(` - ${scope.label}: ${scope.value}`);
}
}
}

Scope Constants

The SDK exports a Scope object with all known scope values as typed constants, preventing typos and enabling autocompletion.

import { Scope } from '@sonar/sdk';

Signed Document Scopes

ConstantValue
Scope.DOCUMENTS_SIGNED_READ"documents:signed:read"
Scope.DOCUMENTS_SIGNED_UPLOAD"documents:signed:upload"
Scope.DOCUMENTS_SIGNED_UPDATE"documents:signed:update"
Scope.DOCUMENTS_SIGNED_EXPORT"documents:signed:export"
Scope.DOCUMENTS_SIGNED_DELETE"documents:signed:delete"

Generated Document Scopes

ConstantValue
Scope.DOCUMENTS_GENERATED_READ"documents:generated:read"
Scope.DOCUMENTS_GENERATED_UPLOAD"documents:generated:upload"
Scope.DOCUMENTS_GENERATED_UPDATE"documents:generated:update"
Scope.DOCUMENTS_GENERATED_EXPORT"documents:generated:export"
Scope.DOCUMENTS_GENERATED_DELETE"documents:generated:delete"

Uploaded Document Scopes

ConstantValue
Scope.DOCUMENTS_UPLOADED_READ"documents:uploaded:read"
Scope.DOCUMENTS_UPLOADED_UPLOAD"documents:uploaded:upload"
Scope.DOCUMENTS_UPLOADED_UPDATE"documents:uploaded:update"
Scope.DOCUMENTS_UPLOADED_EXPORT"documents:uploaded:export"
Scope.DOCUMENTS_UPLOADED_DELETE"documents:uploaded:delete"

Usage with getAllowed()

import { SonarSDK, Scope } from '@sonar/sdk';
const sdk = new SonarSDK({ apiKey: 'sk_...', instanceName: 'demo' });
const { scopes } = await sdk.scopes.getAllowed();
if (scopes.includes(Scope.DOCUMENTS_SIGNED_READ)) {
const signedDocs = await sdk.documents.list({ classification: 'signed' });
}

Permission Matrix

Scope StringConstantCategoryTypeAction
documents:signed:readScope.DOCUMENTS_SIGNED_READDocumentsSignedRead
documents:signed:uploadScope.DOCUMENTS_SIGNED_UPLOADDocumentsSignedUpload
documents:signed:updateScope.DOCUMENTS_SIGNED_UPDATEDocumentsSignedUpdate
documents:signed:exportScope.DOCUMENTS_SIGNED_EXPORTDocumentsSignedExport
documents:signed:deleteScope.DOCUMENTS_SIGNED_DELETEDocumentsSignedDelete
documents:generated:readScope.DOCUMENTS_GENERATED_READDocumentsGeneratedRead
documents:generated:uploadScope.DOCUMENTS_GENERATED_UPLOADDocumentsGeneratedUpload
documents:generated:updateScope.DOCUMENTS_GENERATED_UPDATEDocumentsGeneratedUpdate
documents:generated:exportScope.DOCUMENTS_GENERATED_EXPORTDocumentsGeneratedExport
documents:generated:deleteScope.DOCUMENTS_GENERATED_DELETEDocumentsGeneratedDelete
documents:uploaded:readScope.DOCUMENTS_UPLOADED_READDocumentsUploadedRead
documents:uploaded:uploadScope.DOCUMENTS_UPLOADED_UPLOADDocumentsUploadedUpload
documents:uploaded:updateScope.DOCUMENTS_UPLOADED_UPDATEDocumentsUploadedUpdate
documents:uploaded:exportScope.DOCUMENTS_UPLOADED_EXPORTDocumentsUploadedExport
documents:uploaded:deleteScope.DOCUMENTS_UPLOADED_DELETEDocumentsUploadedDelete