API Integration

Use KnowFlow’s API to build custom integrations and applications that leverage your knowledge bases.

Getting Started

1

Get API Credentials

  1. Navigate to your integration settings
  2. Go to the API tab
  3. Generate API keys and note your integration ID
2

Test Connection

Make a test API call to verify your setup:

curl -X POST "https://api.knowflow.in/v1/integrations/YOUR_INTEGRATION_ID/chat" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello, can you help me?"}'
3

Implement in Your Application

Integrate the API calls into your custom application or service.

API Endpoints

Send Message

Send a message to your integration and receive a response.

POST /v1/integrations/{integrationId}/chat

Request Body:

{
  "message": "How do I reset my password?",
  "sessionId": "user-session-123",
  "metadata": {
    "userId": "user_123",
    "source": "mobile_app"
  }
}

Response:

{
  "response": "To reset your password, follow these steps...",
  "sessionId": "user-session-123",
  "confidence": 0.95,
  "sources": [
    {
      "title": "Password Reset Guide",
      "url": "https://docs.company.com/password-reset"
    }
  ]
}

Get Conversation History

Retrieve conversation history for a session.

GET /v1/integrations/{integrationId}/conversations/{sessionId}

Authentication

All API requests require authentication using an API key:

Authorization: Bearer YOUR_API_KEY

Rate Limiting

API requests are rate limited based on your plan:

PlanRequests per minuteRequests per day
Free601,000
Pro30010,000
Enterprise1,000100,000

SDK Examples

JavaScript/Node.js

const knowflow = require('@knowflow/sdk');

const client = new knowflow.Client({
  apiKey: 'your-api-key',
  integrationId: 'your-integration-id'
});

const response = await client.chat({
  message: 'How can I help you?',
  sessionId: 'user-123'
});

console.log(response.message);

Python

import knowflow

client = knowflow.Client(
    api_key='your-api-key',
    integration_id='your-integration-id'
)

response = client.chat(
    message='How can I help you?',
    session_id='user-123'
)

print(response['message'])

PHP

<?php
use KnowFlow\Client;

$client = new Client([
    'api_key' => 'your-api-key',
    'integration_id' => 'your-integration-id'
]);

$response = $client->chat([
    'message' => 'How can I help you?',
    'session_id' => 'user-123'
]);

echo $response['message'];

Error Handling

The API uses standard HTTP status codes:

StatusMeaning
200Success
400Bad Request - Invalid parameters
401Unauthorized - Invalid API key
429Too Many Requests - Rate limit exceeded
500Internal Server Error

Example error response:

{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "The message parameter is required"
  }
}

Webhooks

Configure webhooks to receive real-time notifications:

Setup

  1. Configure webhook URL in your integration settings
  2. Choose which events to receive notifications for
  3. Verify webhook signature for security

Event Types

  • conversation.started - New conversation initiated
  • conversation.ended - Conversation completed
  • message.received - New message from user
  • message.sent - Response sent to user

Webhook Payload

{
  "event": "message.received",
  "timestamp": "2023-10-15T14:30:00Z",
  "data": {
    "integrationId": "int_123",
    "sessionId": "session_456",
    "message": "Hello, I need help",
    "metadata": {
      "userId": "user_789"
    }
  }
}

Best Practices

  • Use Session IDs: Maintain conversation context with consistent session identifiers
  • Handle Rate Limits: Implement retry logic with exponential backoff
  • Secure API Keys: Store API keys securely and rotate them regularly
  • Monitor Usage: Track API usage to stay within limits
  • Cache Responses: Cache frequently requested information to reduce API calls