TypeScript SDK
TypeScript SDK
The official Flow TypeScript SDK provides a type-safe way to interact with the Flow API.
Installation
npm install @flowdev/sdkQuick Start
import { Flow } from '@flowdev/sdk';
const flow = new Flow('flow_sk_live_...');
// Create a postconst post = await flow.posts.create({ channel: 'your-channel-id', content: 'Hello from Flow!', scheduledFor: new Date().toISOString(),});Client Configuration
const flow = new Flow('flow_sk_live_...', { baseUrl: 'https://api.flowsocial.app', // Optional, defaults to production});Resources
The SDK provides access to these resources:
Posts
// Create a postconst post = await flow.posts.create({ channel: 'channel-id', content: 'Your content here', scheduledFor: '2024-01-15T10:00:00Z',});
// Get a postconst post = await flow.posts.get('post-id');
// List postsconst posts = await flow.posts.list({ channel: 'channel-id' });
// Delete a postawait flow.posts.delete('post-id');Channels
// List channelsconst channels = await flow.channels.list();
// Get a channelconst channel = await flow.channels.get('channel-id');
// Create a channelconst channel = await flow.channels.create({ name: 'My Channel', connectionId: 'connection-id',});Connections
// List connectionsconst connections = await flow.connections.list();
// Get a connectionconst connection = await flow.connections.get('connection-id');Webhooks
// Create a webhookconst webhook = await flow.webhooks.create({ url: 'https://your-app.com/webhook', events: ['post.published', 'post.failed'],});
// List webhooksconst webhooks = await flow.webhooks.list();
// Delete a webhookawait flow.webhooks.delete('webhook-id');API Keys
// List API keysconst keys = await flow.apiKeys.list();
// Create an API keyconst key = await flow.apiKeys.create({ name: 'My Integration',});
// Revoke an API keyawait flow.apiKeys.revoke('key-id');Error Handling
import { Flow, FlowError } from '@flowdev/sdk';
try { await flow.posts.create({ ... });} catch (error) { if (error instanceof FlowError) { console.error('Flow API error:', error.message); console.error('Status:', error.status); console.error('Code:', error.code); }}TypeScript Types
All request and response types are exported:
import type { Post, Channel, Connection, CreatePostRequest, CreateChannelRequest,} from '@flowdev/sdk';