Getting Started
Install the SDK and make your first API call in minutes.
Installation
# npmnpm install @sonar/sdk
# yarnyarn add @sonar/sdk
# pnpmpnpm add @sonar/sdkPeer Dependencies: None
Runtime Dependency: axios ^1.13.4 (bundled)
Quick Start
import { SonarSDK } from '@sonar/sdk';
// Initialize the clientconst sdk = new SonarSDK({ apiKey: 'sk_your_api_key_here', instanceName: 'your-instance',});
// List documentsconst { docs, totalDocs, totalPages } = await sdk.documents.list({ limit: 20 });console.log(`Found ${totalDocs} documents across ${totalPages} pages`);
// Download a documentconst { data, filename, contentType } = await sdk.documents.download('doc_123');
// Upload a documentimport { readFileSync } from 'fs';const file = readFileSync('./contract.pdf');const uploaded = await sdk.documents.upload({ file, filename: 'contract.pdf', contentType: 'application/pdf', classification: 'uploaded', uploadFrom: 'user-documents',});console.log(`Uploaded: ${uploaded.id}`);
// Delete a documentconst { documentId } = await sdk.documents.delete('doc_456');console.log(`Deleted: ${documentId}`);
// Get a presigned download URLconst { url } = await sdk.documents.getDownloadUrl('doc_123', { expiresIn: 600 });console.log(`Download URL: ${url}`);
// Check permissionsconst { scopes } = await sdk.scopes.getAllowed();console.log('Allowed scopes:', scopes);SDK Resources
The SDK exposes two resource namespaces:
| Resource | Accessor | Description |
|---|---|---|
| Documents | sdk.documents | Manage documents — list, get, upload, download, presigned URLs, delete, batch delete, export, signature chains |
| Scopes | sdk.scopes | Query API key permissions and available scopes |
Next Steps
- Configuration — All config options and URL resolution
- Authentication — API key format and validation
- Documents — Full document operations reference