TW

API Documentation

Complete API reference for TW. Build powerful integrations with our comprehensive REST API.

API Documentation

Build powerful integrations with our comprehensive REST API.

Getting Started

Authentication

All API requests require authentication using API keys:

curl https://api.twhelpcenter.com/v1/datasets \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

Base URL

https://api.twhelpcenter.com/v1

Rate Limits

| Plan | Rate Limit | Burst | |------|------------|-------| | Starter | 10 req/sec | 20 | | Pro | 100 req/sec | 200 | | Enterprise | Custom | Custom |

Core Resources

Datasets

List Datasets

GET /datasets
import { TWAPI } from '@tw/sdk';

const api = new TWAPI({ apiKey: process.env.API_KEY });
const datasets = await api.datasets.list({
  limit: 10,
  offset: 0,
  sort: 'created_at:desc'
});

Create Dataset

POST /datasets
const dataset = await api.datasets.create({
  name: 'customer_data',
  description: 'Customer information dataset',
  schema: {
    columns: [
      { name: 'id', type: 'integer', primaryKey: true },
      { name: 'email', type: 'string', unique: true },
      { name: 'name', type: 'string' },
      { name: 'created_at', type: 'timestamp' }
    ]
  }
});

Get Dataset

GET /datasets/:id

Update Dataset

PATCH /datasets/:id

Delete Dataset

DELETE /datasets/:id

Rows

Insert Rows

await api.datasets.insertRows('dataset_id', {
  rows: [
    { id: 1, email: 'user@example.com', name: 'John Doe' },
    { id: 2, email: 'jane@example.com', name: 'Jane Smith' }
  ]
});

Query Rows

const results = await api.datasets.query('dataset_id', {
  select: ['id', 'email', 'name'],
  where: {
    created_at: { gte: '2024-01-01' }
  },
  orderBy: { created_at: 'desc' },
  limit: 100
});

Update Rows

await api.datasets.updateRows('dataset_id', {
  where: { id: 1 },
  data: { name: 'John Updated' }
});

Delete Rows

await api.datasets.deleteRows('dataset_id', {
  where: { id: { in: [1, 2, 3] } }
});

Policies

Create Policy

const policy = await api.policies.create({
  name: 'PII Access Control',
  description: 'Restrict access to PII fields',
  rules: [
    {
      resource: 'datasets.customer_data.pii_fields',
      action: 'read',
      effect: 'deny',
      condition: 'user.role != "admin"'
    }
  ],
  active: true
});

List Policies

GET /policies

Evaluate Policy

const result = await api.policies.evaluate({
  policy_id: 'policy_123',
  resource: 'datasets.customer_data',
  action: 'read',
  context: {
    user: { role: 'analyst', department: 'marketing' }
  }
});

console.log(result.allowed); // true or false
console.log(result.reason); // Explanation

Integrations

List Integrations

const integrations = await api.integrations.list();

Connect Integration

await api.integrations.connect('slack', {
  webhook_url: 'https://hooks.slack.com/...',
  channel: '#notifications'
});

Trigger Integration

await api.integrations.trigger('slack', {
  action: 'send_message',
  payload: {
    text: 'Dataset updated successfully'
  }
});

Webhooks

Create Webhook

const webhook = await api.webhooks.create({
  url: 'https://your-server.com/webhooks',
  events: ['dataset.created', 'dataset.updated'],
  secret: 'your_webhook_secret'
});

Webhook Payload Example

{
  "id": "evt_123",
  "type": "dataset.updated",
  "created_at": "2024-03-15T10:30:00Z",
  "data": {
    "dataset_id": "ds_456",
    "name": "customer_data",
    "changes": {
      "rows_added": 150,
      "rows_updated": 23,
      "rows_deleted": 5
    }
  }
}

Verify Webhook Signature

import crypto from 'crypto';

function verifyWebhook(payload, signature, secret) {
  const hmac = crypto.createHmac('sha256', secret);
  const digest = hmac.update(payload).digest('hex');
  return crypto.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(digest)
  );
}

Batch Operations

Batch Insert

const batch = api.batch();
batch.datasets.create({ name: 'dataset1' });
batch.datasets.create({ name: 'dataset2' });
batch.datasets.insertRows('existing_dataset', { rows: [...] });

const results = await batch.execute();

Error Handling

try {
  await api.datasets.create(datasetConfig);
} catch (error) {
  if (error.code === 'RATE_LIMIT_EXCEEDED') {
    console.log('Rate limit exceeded, retry after:', error.retryAfter);
  } else if (error.code === 'VALIDATION_ERROR') {
    console.log('Validation errors:', error.errors);
  } else {
    console.log('Unexpected error:', error.message);
  }
}

Error Codes

| Code | Description | |------|-------------| | 400 | Bad Request - Invalid parameters | | 401 | Unauthorized - Invalid API key | | 403 | Forbidden - Insufficient permissions | | 404 | Not Found - Resource doesn't exist | | 429 | Rate Limit Exceeded | | 500 | Internal Server Error |

Pagination

// Offset-based pagination
const page1 = await api.datasets.list({ limit: 10, offset: 0 });
const page2 = await api.datasets.list({ limit: 10, offset: 10 });

// Cursor-based pagination
const page1 = await api.datasets.list({ limit: 10 });
const page2 = await api.datasets.list({
  limit: 10,
  cursor: page1.next_cursor
});

Filtering & Sorting

const results = await api.datasets.list({
  filter: {
    name: { contains: 'customer' },
    created_at: { gte: '2024-01-01' }
  },
  sort: [
    { field: 'created_at', order: 'desc' },
    { field: 'name', order: 'asc' }
  ]
});

SDKs

Official SDKs available:

  • JavaScript/TypeScript
  • Python
  • Ruby
  • Go
  • Java
  • PHP

API Playground

Try our interactive API playground at https://api.twhelpcenter.com/playground

OpenAPI Specification

Download our OpenAPI spec: https://api.twhelpcenter.com/openapi.json

Learn More