# PandaDoc

PandaDoc is a document automation and eSignature platform. The Sling PandaDoc connector extracts data from the PandaDoc API, supporting documents, templates, contacts, members, forms, folders, workspaces, and more.

{% hint style="success" %}
**CLI Pro Required**: APIs require a [CLI Pro token](https://docs.slingdata.io/sling-cli/cli-pro) or [Platform Plan](https://docs.slingdata.io/sling-platform/platform).
{% endhint %}

## Setup

The following credentials and inputs are accepted:

**Secrets:**

* `api_key` **(required)** -> Your PandaDoc Sandbox or Production API key

**Inputs:**

* `anchor_date` (optional) -> The starting date for historical data extraction (default: 1 year ago). Format: `YYYY-MM-DDTHH:MM:SSZ`

### Getting Your API Key

PandaDoc provides a free Sandbox API key with trial accounts:

1. Sign up for a free trial at <https://signup.pandadoc.com/>
2. Go to **Settings** > **API and Integrations**
3. Click on **API and Webhooks**
4. Click **Enable** to activate the API
5. Click **Open** to access the Dev Center
6. Under **API keys**, click **Generate** next to **Sandbox key**
7. Copy the generated key

{% hint style="info" %}
**Sandbox vs Production:** The Sandbox key is rate-limited to 10 requests per minute and adds a `[DEV]` prefix to documents. Production keys require an Enterprise plan.
{% endhint %}

### Using `sling conns`

{% code overflow="wrap" %}

```bash
sling conns set PANDADOC type=api spec=pandadoc secrets='{ api_key: your_api_key_here }'
```

{% endcode %}

### Environment Variable

See [here](https://docs.slingdata.io/sling-cli/environment#dot-env-file-.env.sling) to learn more about the `.env.sling` file.

{% code overflow="wrap" %}

```bash
export PANDADOC='{ type: api, spec: pandadoc, secrets: { api_key: "your_api_key_here" } }'
```

{% endcode %}

### Sling Env File YAML

See [here](https://docs.slingdata.io/sling-cli/environment#sling-env-file-env.yaml) to learn more about the sling `env.yaml` file.

```yaml
connections:
  PANDADOC:
    type: api
    spec: pandadoc
    secrets:
      api_key: "your_api_key_here"
```

**With anchor date for historical data:**

```yaml
connections:
  PANDADOC:
    type: api
    spec: pandadoc
    secrets:
      api_key: "your_api_key_here"
    inputs:
      anchor_date: "2024-01-01T00:00:00Z"
```

## Replication

Here's an example replication configuration to sync PandaDoc to a PostgreSQL database:

```yaml
source: PANDADOC
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: public.pandadoc_{stream_name}

streams:
  # sync all endpoints
  '*':

  # incremental sync for documents
  documents:
    mode: incremental
    primary_key: [id]
    update_key: date_modified
```

## Endpoints

| Endpoint                | Description                                                              | Incremental             |
| ----------------------- | ------------------------------------------------------------------------ | ----------------------- |
| `documents`             | All documents with metadata                                              | Yes (`date_modified`)   |
| `document_details`      | Detailed document info including fields, recipients, tokens, and pricing | No (child of documents) |
| `document_fields`       | Fields for each document                                                 | No (child of documents) |
| `document_attachments`  | Attachments for each document                                            | No (child of documents) |
| `document_sections`     | Sections/bundles for each document                                       | No (child of documents) |
| `templates`             | All document templates                                                   | No                      |
| `contacts`              | All contacts                                                             | No                      |
| `members`               | Workspace members                                                        | No                      |
| `forms`                 | All forms                                                                | No                      |
| `document_folders`      | Document folder hierarchy                                                | No                      |
| `template_folders`      | Template folder hierarchy                                                | No                      |
| `api_logs`              | API request logs                                                         | No                      |
| `webhook_subscriptions` | Webhook subscription configurations                                      | No                      |
| `webhook_events`        | Webhook event history                                                    | No                      |
| `workspaces`            | All workspaces                                                           | No                      |

## Incremental Sync

The `documents` endpoint supports incremental sync using the `date_modified` field. On first sync, it fetches all documents modified since `anchor_date` (default: 1 year ago). Subsequent syncs fetch only documents modified since the last successful sync.

If you are facing issues connecting, please reach out to us at <support@slingdata.io>, on [discord](https://discord.gg/q5xtaSNDvp) or open a Github Issue [here](https://github.com/slingdata-io/sling-cli/issues).
