Skip to content

TypeScript SDK

TypeScript SDK

The official Flow TypeScript SDK provides a type-safe way to interact with the Flow API.

Installation

Terminal window
npm install @flowdev/sdk

Quick Start

import { Flow } from '@flowdev/sdk';
const flow = new Flow('flow_sk_live_...');
// Create a post
const 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 post
const post = await flow.posts.create({
channel: 'channel-id',
content: 'Your content here',
scheduledFor: '2024-01-15T10:00:00Z',
});
// Get a post
const post = await flow.posts.get('post-id');
// List posts
const posts = await flow.posts.list({ channel: 'channel-id' });
// Delete a post
await flow.posts.delete('post-id');

Channels

// List channels
const channels = await flow.channels.list();
// Get a channel
const channel = await flow.channels.get('channel-id');
// Create a channel
const channel = await flow.channels.create({
name: 'My Channel',
connectionId: 'connection-id',
});

Connections

// List connections
const connections = await flow.connections.list();
// Get a connection
const connection = await flow.connections.get('connection-id');

Webhooks

// Create a webhook
const webhook = await flow.webhooks.create({
url: 'https://your-app.com/webhook',
events: ['post.published', 'post.failed'],
});
// List webhooks
const webhooks = await flow.webhooks.list();
// Delete a webhook
await flow.webhooks.delete('webhook-id');

API Keys

// List API keys
const keys = await flow.apiKeys.list();
// Create an API key
const key = await flow.apiKeys.create({
name: 'My Integration',
});
// Revoke an API key
await 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';