> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pictify.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Bindings

> Connect templates to external data sources for automatic rendering

# Bindings

Bindings connect templates to external data sources, enabling automatic image generation when data changes. Perfect for dynamic dashboards, real-time stats, and automated social media images.

<Note>
  For a step-by-step tutorial, see [Webhook Integration](/guides/webhook-integration).
</Note>

## How Bindings Work

```
[Your Data API] → [Binding] → [Template] → [Updated Image]
```

1. **Create a binding** -- link a template to an external data URL
2. **Pictify fetches data** -- based on your refresh policy
3. **Template renders** -- variables from the data are injected into the template
4. **Image updates** -- the rendered image URL stays the same, content updates automatically

## Endpoints

| Method   | Endpoint          | Description                                                |
| -------- | ----------------- | ---------------------------------------------------------- |
| `GET`    | `/bindings`       | [List bindings](/api-reference/endpoints/bindings/list)    |
| `POST`   | `/bindings`       | [Create binding](/api-reference/endpoints/bindings/create) |
| `GET`    | `/bindings/{uid}` | [Get binding](/api-reference/endpoints/bindings/get)       |
| `PUT`    | `/bindings/{uid}` | [Update binding](/api-reference/endpoints/bindings/update) |
| `DELETE` | `/bindings/{uid}` | [Delete binding](/api-reference/endpoints/bindings/delete) |

## Binding Status

| Status   | Description                      |
| -------- | -------------------------------- |
| `active` | Binding is active and refreshing |
| `paused` | Temporarily disabled             |
| `error`  | Failed to fetch data or render   |

## Refresh Policy Types

| Type      | Description                                                     |
| --------- | --------------------------------------------------------------- |
| `ttl`     | Refresh after time-to-live expires (default, 60-604800 seconds) |
| `etag`    | Refresh when ETag changes                                       |
| `webhook` | Refresh when webhook is triggered                               |
| `manual`  | Only refresh when manually triggered                            |

## Data Mapping

Map fields from your API response to template variables using dot notation and array access:

```json theme={null}
{
  "mapping": {
    "title": "name",
    "stars": "stargazers_count",
    "userName": "user.name",
    "firstItem": "items[0].name"
  }
}
```

## Data Source Authentication

| Type            | Description                          |
| --------------- | ------------------------------------ |
| `api_key`       | API key authentication               |
| `bearer_token`  | Bearer token in Authorization header |
| `basic_auth`    | Username/password authentication     |
| `custom_header` | Custom header name and value         |

## Binding Events

Subscribe to binding events via [Webhooks](/api-reference/webhooks):

| Event             | Description                    |
| ----------------- | ------------------------------ |
| `binding.updated` | Binding successfully refreshed |
| `binding.failed`  | Binding refresh failed         |

## Best Practices

1. **Set appropriate TTL** -- don't refresh more often than data changes
2. **Use defaults** -- provide fallback values for missing fields
3. **Handle errors gracefully** -- use `serve_stale` for critical images
4. **Monitor binding health** -- set up webhooks for `binding.failed` events
5. **Test before deploying** -- validate your data source and mapping first


## OpenAPI

````yaml get /bindings
openapi: 3.1.0
info:
  title: Pictify API
  version: 1.0.0
  description: |
    Generate images, GIFs, and PDFs from HTML templates programmatically.

    ## Authentication
    All API requests require a Bearer token in the Authorization header:
    ```
    Authorization: Bearer pk_live_your_api_key
    ```

    ## Rate Limits
    - Free: 60 requests/minute
    - Pro: 300 requests/minute
    - Business: 1,000 requests/minute

    Rate limit headers are included in all responses.
  contact:
    email: support@pictify.io
    url: https://pictify.io
  license:
    name: MIT
servers:
  - url: https://api.pictify.io
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Images
    description: Image generation endpoints
  - name: GIFs
    description: GIF generation and capture
  - name: PDFs
    description: PDF generation
  - name: Templates
    description: Template management
  - name: Batch
    description: Batch rendering operations
  - name: Experiments
    description: A/B testing, smart links, and scheduled variant experiments
  - name: Webhooks
    description: Webhook subscription management
  - name: Bindings
    description: Data binding for auto-rendering
paths:
  /bindings:
    get:
      tags:
        - Bindings
      summary: List bindings
      operationId: listBindings
      parameters:
        - name: templateId
          in: query
          schema:
            type: string
        - name: status
          in: query
          schema:
            type: string
            enum:
              - active
              - paused
              - error
        - name: page
          in: query
          schema:
            type: integer
            default: 1
        - name: limit
          in: query
          schema:
            type: integer
            default: 20
      responses:
        '200':
          description: List of bindings
          content:
            application/json:
              schema:
                type: object
                properties:
                  bindings:
                    type: array
                    items:
                      $ref: '#/components/schemas/Binding'
                  pagination:
                    $ref: '#/components/schemas/Pagination'
components:
  schemas:
    Binding:
      type: object
      properties:
        uid:
          type: string
        name:
          type: string
        templateId:
          type: string
        dataSource:
          type: object
          properties:
            type:
              type: string
              enum:
                - http
                - webhook
                - static
            url:
              type: string
              format: uri
            method:
              type: string
              enum:
                - GET
                - POST
        mapping:
          type: object
          additionalProperties:
            type: string
        defaults:
          type: object
          additionalProperties: true
        refreshPolicy:
          type: object
          properties:
            type:
              type: string
              enum:
                - ttl
                - etag
                - webhook
                - manual
            ttlSeconds:
              type: integer
            onError:
              type: string
              enum:
                - serve_stale
                - serve_error
                - serve_default
        status:
          type: string
          enum:
            - active
            - paused
            - error
        renderUrl:
          type: string
          format: uri
        webhookUrl:
          type: string
          format: uri
        createdAt:
          type: string
          format: date-time
    Pagination:
      type: object
      properties:
        page:
          type: integer
        limit:
          type: integer
        total:
          type: integer
        totalPages:
          type: integer
        hasNext:
          type: boolean
        hasPrev:
          type: boolean
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API key obtained from the Pictify dashboard

````