SDK Installation & Quick Start

Integrate the ConnectHub SDK into your application to access the full power of the social platform. Create posts, manage communities, stream live content, and interact with users programmatically.

â„šī¸
Note: The SDK requires ConnectHub API v2.4 or higher. Ensure your project is running Node.js 18+ or equivalent runtime for other languages.

Installation

Install the ConnectHub SDK using your preferred package manager. We support JavaScript/TypeScript, Python, Swift, and Kotlin.

npm
npm install @connecthub/sdk

For TypeScript users, types are included automatically.

pip
pip install connecthub-sdk
Swift Package Manager
package.dependencies.append(
    .package(url: "https://github.com/connecthub/sdk-swift.git", from: "2.4.0")
)
Gradle
implementation("com.connecthub:sdk-kotlin:2.4.0")

Quick Start

Get up and running in less than a minute. Initialize the client with your API key and make your first request.

Node.js
import { ConnectHub } from '@connecthub/sdk';

// Initialize the client
const hub = new ConnectHub({
    apiKey: process.env.CONNECTHUB_API_KEY,
    environment: 'production'  // or 'sandbox'});

// Fetch authenticated user profile
async function getUser() {
    try {
        const user = await hub.users.get('me');
        console.log(`Logged in as: ${user.username}`);
        console.log(`Followers: ${user.stats.followers}`);
    } catch (error) {
        console.error('Failed to fetch user', error);
    }
}

getUser();
Python 3
import connecthub

# Initialize the client
hub = connecthub.Client(
    api_key=os.environ["CONNECTHUB_API_KEY"],
    environment="production"
)

# Fetch authenticated user profile
try:
    user = hub.users.get("me")
    print(f"Logged in as: {user.username}")
    print(f"Followers: {user.stats.followers}")
except connecthub.AuthenticationError:
    print("Invalid API key")

Creating Content

Use the SDK to publish posts, stories, and media to your profile or on behalf of a community.

POST /v2/posts

Create a new post with text, media, and engagement settings.

Parameter Type Description
body Required String The text content of the post (max 280 chars)
media_ids String[] Array of uploaded media IDs
visibility Enum public, followers, or private
community_id String Post to a specific community instead of personal profile
SDK Usage
// Create a post with an image
const post = await hub.posts.create({
    body: 'Just launched our new feature! 🚀 @connecthub',
    media_ids: ['img_8x92js'],
    visibility: 'public',
    tags: ['launch', 'connecthub']
});

console.log(`Post created: ${post.id}`);
SDK Usage
# Create a post with an image
post = hub.posts.create(
    body="Just launched our new feature! 🚀 @connecthub",
    media_ids=["img_8x92js"],
    visibility="public",
    tags=["launch", "connecthub"]
)

print(f"Post created: {post.id}")

Error Handling

The SDK throws typed errors to help you handle failures gracefully. Always wrap async calls in try-catch blocks.

âš ī¸
Rate Limits: API requests are limited to 100 requests per minute per token. The SDK automatically retries 429 errors with exponential backoff.
Error Types
const { ConnectHubError } = require('@connecthub/sdk/errors');

try {
    await hub.posts.create({ body: 'Hello' });
} catch (error) {
    if (error instanceof ConnectHubError) {
        console.log(`Error code: ${error.code}`);
        console.log(`Message: ${error.message}`);
        
        if (error.code === 'RATE_LIMITED') {
            // Implement backoff strategy
        }
    }
}
🚨
Security Warning: Never expose your API key in client-side code. Use environment variables or a backend proxy for sensitive operations.