API Reference

The Data Publisher for Word API allows you to programmatically create, manage, and generate documents using your data sources. Build powerful integrations and automate document workflows.

Base URL

https://api.db2word.com/v1

Authentication

The Data Publisher API uses API keys for authentication. You can obtain your API key from your account dashboard.

API Key Authentication

Include your API key in the Authorization header of each request:

HTTP Header

Authorization: Bearer YOUR_API_KEY

Getting Your API Key

  1. Log in to your Data Publisher account
  2. Navigate to SettingsAPI Keys
  3. Click "Generate New API Key"
  4. Copy and securely store your API key

Security Note

Keep your API key secure and never expose it in client-side code. Use environment variables or secure key management systems in production.

Rate Limiting

API requests are rate limited to ensure fair usage and system stability:

Plan Requests per Minute Requests per Hour
Individual 60 2,000
Professional 300 10,000
Business 600 25,000
Enterprise 1,200 100,000

Rate limit headers are included in each response:

X-RateLimit-Limit: 300
X-RateLimit-Remaining: 299
X-RateLimit-Reset: 1641024000

API Endpoints

Documents

POST /documents

Create a new document from a template and data source.

Request Body

{
  "template_id": "template_123",
  "data_source": {
    "type": "csv",
    "data": [
      {"name": "John Doe", "email": "john@example.com"},
      {"name": "Jane Smith", "email": "jane@example.com"}
    ]
  },
  "options": {
    "format": "docx",
    "filename": "employee_directory.docx"
  }
}

Response

{
  "document_id": "doc_456",
  "status": "processing",
  "download_url": null,
  "created_at": "2025-09-07T10:30:00Z"
}
GET /documents/{document_id}

Get document status and download URL.

Response

{
  "document_id": "doc_456",
  "status": "completed",
  "download_url": "https://api.db2word.com/v1/documents/doc_456/download",
  "created_at": "2025-09-07T10:30:00Z",
  "completed_at": "2025-09-07T10:31:45Z",
  "page_count": 3,
  "file_size": 156782
}
GET /documents

List all documents with pagination.

Query Parameters

  • page - Page number (default: 1)
  • limit - Items per page (default: 50, max: 100)
  • status - Filter by status (processing, completed, failed)

Templates

GET /templates

List available templates.

Response

{
  "templates": [
    {
      "template_id": "template_123",
      "name": "Employee Directory",
      "description": "Professional employee directory template",
      "category": "HR",
      "fields": ["name", "email", "department", "phone"],
      "created_at": "2025-08-15T09:00:00Z"
    }
  ],
  "total": 25,
  "page": 1,
  "pages": 3
}
POST /templates

Upload a custom template.

Request (Multipart Form Data)

  • file - Word document file (.docx)
  • name - Template name
  • description - Template description
  • category - Template category

Data Sources

POST /data-sources

Create a reusable data source connection.

Request Body (Database)

{
  "name": "Customer Database",
  "type": "database",
  "config": {
    "provider": "sqlserver",
    "host": "server.example.com",
    "database": "CustomerDB",
    "username": "api_user",
    "password": "secure_password",
    "port": 1433
  },
  "query": "SELECT * FROM customers WHERE active = 1"
}

Request Body (API)

{
  "name": "CRM API",
  "type": "api",
  "config": {
    "url": "https://api.crm.example.com/customers",
    "method": "GET",
    "headers": {
      "Authorization": "Bearer token123",
      "Content-Type": "application/json"
    }
  }
}

Code Examples

JavaScript/Node.js

Create Document

const axios = require('axios');

const apiKey = 'your_api_key_here';
const baseURL = 'https://api.db2word.com/v1';

async function createDocument() {
  try {
    const response = await axios.post(`${baseURL}/documents`, {
      template_id: 'template_123',
      data_source: {
        type: 'csv',
        data: [
          { name: 'John Doe', email: 'john@example.com' },
          { name: 'Jane Smith', email: 'jane@example.com' }
        ]
      },
      options: {
        format: 'docx',
        filename: 'employees.docx'
      }
    }, {
      headers: {
        'Authorization': `Bearer ${apiKey}`,
        'Content-Type': 'application/json'
      }
    });
    
    console.log('Document created:', response.data);
    return response.data.document_id;
  } catch (error) {
    console.error('Error:', error.response.data);
  }
}

async function getDocumentStatus(documentId) {
  try {
    const response = await axios.get(`${baseURL}/documents/${documentId}`, {
      headers: {
        'Authorization': `Bearer ${apiKey}`
      }
    });
    
    return response.data;
  } catch (error) {
    console.error('Error:', error.response.data);
  }
}

Python

Create Document

import requests
import json

API_KEY = 'your_api_key_here'
BASE_URL = 'https://api.db2word.com/v1'

def create_document():
    headers = {
        'Authorization': f'Bearer {API_KEY}',
        'Content-Type': 'application/json'
    }
    
    data = {
        'template_id': 'template_123',
        'data_source': {
            'type': 'csv',
            'data': [
                {'name': 'John Doe', 'email': 'john@example.com'},
                {'name': 'Jane Smith', 'email': 'jane@example.com'}
            ]
        },
        'options': {
            'format': 'docx',
            'filename': 'employees.docx'
        }
    }
    
    response = requests.post(f'{BASE_URL}/documents', 
                           headers=headers, 
                           json=data)
    
    if response.status_code == 201:
        result = response.json()
        print(f"Document created: {result['document_id']}")
        return result['document_id']
    else:
        print(f"Error: {response.status_code} - {response.text}")
        return None

def get_document_status(document_id):
    headers = {
        'Authorization': f'Bearer {API_KEY}'
    }
    
    response = requests.get(f'{BASE_URL}/documents/{document_id}', 
                          headers=headers)
    
    if response.status_code == 200:
        return response.json()
    else:
        print(f"Error: {response.status_code} - {response.text}")
        return None

cURL

Create Document

curl -X POST https://api.db2word.com/v1/documents \
  -H "Authorization: Bearer your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "template_123",
    "data_source": {
      "type": "csv",
      "data": [
        {"name": "John Doe", "email": "john@example.com"},
        {"name": "Jane Smith", "email": "jane@example.com"}
      ]
    },
    "options": {
      "format": "docx",
      "filename": "employees.docx"
    }
  }'

Official SDKs

We provide official SDKs for popular programming languages to make integration easier:

JavaScript/Node.js

npm install @db2word/api-client

View on GitHub

Python

pip install db2word-api

View on GitHub

C# / .NET

dotnet add package DB2Word.Api

View on GitHub

PHP

composer require db2word/api-client

View on GitHub

Error Handling

The API uses conventional HTTP response codes to indicate success or failure:

HTTP Status Codes

Code Meaning Description
200 OK Request successful
201 Created Resource created successfully
400 Bad Request Invalid request parameters
401 Unauthorized Invalid or missing API key
403 Forbidden Access denied
404 Not Found Resource not found
429 Too Many Requests Rate limit exceeded
500 Internal Server Error Server error

Error Response Format

Error responses include details to help you understand and resolve the issue:

{
  "error": {
    "code": "INVALID_TEMPLATE",
    "message": "The specified template was not found",
    "details": {
      "template_id": "template_999",
      "suggestion": "Check that the template ID is correct and that you have access to it"
    },
    "request_id": "req_12345",
    "timestamp": "2025-09-07T10:30:00Z"
  }
}

Common Error Codes

  • INVALID_API_KEY - The API key is invalid or expired
  • RATE_LIMIT_EXCEEDED - Too many requests, slow down
  • INVALID_TEMPLATE - Template not found or inaccessible
  • INVALID_DATA_SOURCE - Data source configuration is invalid
  • PROCESSING_FAILED - Document generation failed
  • INSUFFICIENT_CREDITS - Account has insufficient credits

Need Help with the API?

Our developer support team is here to help you integrate successfully: