SDK Usage Examples¶
This guide provides practical examples for common SDK operations.
Installation¶
Authentication Setup¶
OAuth (User Operations)¶
Use OAuth authentication when your application needs to access user-specific data like meetings and action items:
import { ContioPartnerSDK } from '@contio/partner-sdk';
const sdk = ContioPartnerSDK.forUser({
clientId: process.env.OAUTH_CLIENT_ID,
clientSecret: process.env.OAUTH_CLIENT_SECRET,
redirectUri: 'https://your-app.com/callback'
});
API Key (Admin Operations)¶
Use API key authentication for administrative operations like connection management:
Basic Operations¶
List Meetings¶
async function listMeetings() {
const meetings = await sdk.user.getMeetings({
limit: 10,
offset: 0
});
console.log(`Found ${meetings.total} meetings`);
meetings.items.forEach(meeting => {
console.log(`- ${meeting.title} (${meeting.status})`);
});
}
Create Action Item¶
async function createActionItem(meetingId: string) {
const actionItem = await sdk.user.createActionItem({
meeting_id: meetingId,
description: 'Follow up with client about proposal',
due_date: '2023-12-31T17:00:00Z',
partner_context: {
priority: 'high',
category: 'sales'
}
});
console.log('Created action item:', actionItem.id);
}
Create Automation¶
async function createAutomation() {
const automation = await sdk.admin.createWAutomation({
name: 'CRM Sync',
description: 'Sync action items to CRM',
trigger_type: 'action_item_created',
actions: [{
type: 'webhook',
config: {
url: 'https://your-app.com/webhook',
method: 'POST',
headers: {
'Authorization': 'Bearer your-token'
}
}
}]
});
console.log('Created automation:', automation.id);
}
Error Handling¶
The SDK provides typed errors for better error handling:
import { ContioAPIError } from '@contio/partner-sdk';
try {
const meeting = await sdk.user.getMeeting('invalid-id');
} catch (error) {
if (error instanceof ContioAPIError) {
console.error(`API Error [${error.code}]: ${error.message}`);
console.error('Status:', error.statusCode);
// Handle specific error codes
switch (error.code) {
case 'not_found':
console.log('Meeting does not exist');
break;
case 'unauthorized':
console.log('Token expired or invalid');
break;
case 'forbidden':
console.log('Insufficient permissions');
break;
}
} else {
console.error('Unexpected error:', error);
}
}
Pagination¶
Most list endpoints support pagination:
async function getAllMeetings() {
const allMeetings = [];
let offset = 0;
const limit = 50;
while (true) {
const response = await sdk.user.getMeetings({ limit, offset });
allMeetings.push(...response.items);
if (response.items.length < limit) {
break; // No more pages
}
offset += limit;
}
return allMeetings;
}
Toolkit Operations (v1.5+)¶
Toolkits bundle templates, next steps, and action buttons into deployable packages.
Create and Install a Toolkit¶
// Define your manifest
const manifest = {
templates: [
{
$id: 'sales-call',
name: 'Sales Discovery Call',
description: 'Structured sales meeting with follow-up automation',
next_steps: [
{ next_step: { $ref: 'summary-step' }, order: 1 }
]
}
],
next_steps: [
{
$id: 'summary-step',
name: 'Generate Call Summary',
type: 'ai',
prompt: 'Summarize this sales call with key discussion points and next actions.',
action_buttons: [
{ action_button: { $ref: 'email-btn' }, order: 1 },
{ action_button: { $ref: 'copy-btn' }, order: 2 }
]
}
],
action_buttons: [
{
$id: 'email-btn',
name: 'Email Summary',
delivery_type: 'email'
},
{
$id: 'copy-btn',
name: 'Copy to Clipboard',
delivery_type: 'clipboard'
}
]
};
// Create toolkit via Admin API
const adminSdk = ContioPartnerSDK.forAdmin({ apiKey: process.env.API_KEY });
const toolkit = await adminSdk.admin.createToolkit({
name: 'Sales Workflow Toolkit',
description: 'Post-meeting follow-up automation for sales teams',
manifest
});
console.log('Created toolkit:', toolkit.id);
// Install on a workspace
await adminSdk.admin.installToolkit(toolkit.id, {
workspace_id: 'ws_abc123'
});
List Available Templates¶
const userSdk = ContioPartnerSDK.forUser({
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
redirectUri: 'https://your-app.com/callback'
});
// Get templates available to the user
const templates = await userSdk.user.getMeetingTemplates();
templates.items.forEach(template => {
console.log(`- ${template.name}: ${template.description}`);
});
Execute Meeting Next Steps¶
After a meeting ends, execute AI-powered next steps:
async function executeNextSteps(meetingId: string) {
// Get available next steps for this meeting
const nextSteps = await userSdk.user.getMeetingNextSteps(meetingId);
for (const step of nextSteps.items) {
console.log(`Executing: ${step.name}`);
// Execute the next step (triggers AI processing)
const execution = await userSdk.user.executeNextStep(meetingId, step.id);
console.log('Execution started:', execution.execution_id);
// Poll for result (AI processing is async)
let result;
do {
await new Promise(resolve => setTimeout(resolve, 2000));
result = await userSdk.user.getNextStepResult(meetingId, step.id);
} while (result.status === 'processing');
if (result.status === 'completed') {
console.log('AI Output:', result.output);
} else {
console.error('Execution failed:', result.error);
}
}
}
Trigger Action Buttons¶
Deliver content via action buttons:
async function deliverViaMail(meetingId: string, actionButtonId: string) {
// Get action buttons for the meeting
const buttons = await userSdk.user.getMeetingActionButtons(meetingId);
// Trigger a specific action button
const result = await userSdk.user.triggerActionButton(meetingId, actionButtonId, {
recipient_email: 'client@example.com',
subject: 'Meeting Summary'
});
console.log('Delivery status:', result.status);
}
Manage Toolkits (Admin)¶
// List all toolkits
const toolkits = await adminSdk.admin.getToolkits();
// Get toolkit details
const toolkit = await adminSdk.admin.getToolkit(toolkitId);
// Update toolkit manifest
await adminSdk.admin.updateToolkit(toolkitId, {
name: 'Updated Name',
manifest: updatedManifest
});
// Uninstall from workspace
await adminSdk.admin.uninstallToolkit(toolkitId, {
workspace_id: 'ws_abc123'
});
// Delete toolkit entirely
await adminSdk.admin.deleteToolkit(toolkitId);
Next Steps¶
- OAuth 2.0 Flow - Implement user authentication
- Toolkits - Complete toolkit and manifest documentation
- Automation Setup - Configure automated action item handling
- Webhook Events - Handle real-time notifications
- API Guide - Complete API reference