# Zapier Integration

### Overview

CSV Getter endpoints are standard URLs that return data. In Zapier, you use the **Webhooks by Zapier** action to fetch data from your endpoint URL. This lets you:

* Pull Airtable/Notion data into any Zapier-supported app
* Run exports on a schedule (hourly, daily, weekly)
* Trigger exports when something happens in another app
* Chain CSV Getter output into downstream actions (email, Slack, Google Sheets, etc.)

***

### Step-by-Step: Fetch CSV Getter Data in Zapier

#### Step 1: Create a Zap

1. Log in to [zapier.com](https://zapier.com) and click **Create Zap**.
2. Choose your **Trigger**:
   * **Schedule by Zapier** — Run on a schedule (every hour, day, week, etc.)
   * **Any other trigger** — Run when something happens in another app

#### Step 2: Add a Webhooks Action

1. Click **+** to add an action step.
2. Search for **Webhooks by Zapier**.
3. Choose **GET** as the action event.
4. Click **Continue**.

#### Step 3: Configure the Request

**URL:** Paste your CSV Getter endpoint URL:

```
https://api.csvgetter.com/abc123def456
```

**To add URL parameters**, append them directly to the URL:

```
https://api.csvgetter.com/abc123def456?type=json_records&sql=SELECT * FROM csvgetter WHERE status='Active'
```

**Headers (if auth is enabled on your endpoint):**

| Key             | Value                      |
| --------------- | -------------------------- |
| `Authorization` | `Bearer your-secret-token` |

Leave all other fields at their defaults:

* **Payload Type:** None
* **Data:** (leave empty)

#### Step 4: Test the Action

1. Click **Test step**.
2. You should see your data returned in the response body.
3. If using JSON format (`?type=json_records`), Zapier will automatically parse the fields.

> **Tip:** Use `?type=json_records` for Zapier integrations. JSON is much easier for Zapier to parse and use in downstream steps than CSV.

#### Step 5: Use the Data in Downstream Actions

Once the Webhooks step returns data, you can use it in subsequent Zapier actions:

* **Gmail / Email** — Send the data as an email body or attachment
* **Google Sheets** — Write rows to a spreadsheet
* **Slack** — Post a summary message
* **Any app** — Map the JSON fields to the app's input fields

***

### Example: Daily Export to Google Sheets via Zapier

#### Trigger: Schedule by Zapier

* **Frequency:** Every day
* **Time:** 9:00 AM

#### Action 1: Webhooks by Zapier (GET)

* **URL:** `https://api.csvgetter.com/abc123?type=json_records`

#### Action 2: Google Sheets — Create Spreadsheet Row

* Map fields from the webhook response to columns in your Google Sheet.

***

### Example: Zapier Code Step (Advanced)

If you need more control, use a **Code by Zapier** step (JavaScript):

```javascript
const response = await fetch("https://api.csvgetter.com/abc123?type=json_records", {
  headers: {
    "Authorization": "Bearer your-token-here"  // only if auth is enabled
  }
});

const data = await response.json();

// Return the first record as output fields
// Or process the data as needed
return {
  total_records: data.length,
  first_name: data[0]?.name || "No data",
  first_email: data[0]?.email || "No data",
  all_data: JSON.stringify(data)
};
```

Or in Python:

```python
import requests

response = requests.get(
    "https://api.csvgetter.com/abc123?type=json_records",
    headers={"Authorization": "Bearer your-token-here"}  # only if auth is enabled
)

data = response.json()

return {
    "total_records": len(data),
    "first_name": data[0].get("name", "No data") if data else "No data",
    "all_data": str(data)
}
```

***

### Error Handling in Zapier

If your CSV Getter endpoint returns an error (non-200 status code), the Zapier step will fail. Common causes:

| Error            | Zapier Behavior | Fix                                    |
| ---------------- | --------------- | -------------------------------------- |
| 401 (Auth error) | Step fails      | Check Bearer token in headers          |
| 403 (No credits) | Step fails      | Purchase more credits at csvgetter.com |
| 400 (Bad SQL)    | Step fails      | Fix the SQL query in your URL          |
| 404 (Not found)  | Step fails      | Verify endpoint ID in the URL          |

**To handle errors gracefully:**

1. In your Zap, click on the Webhooks step.
2. Enable **Continue on error** (in advanced settings).
3. Add a downstream action that checks the status code and sends an alert if it's not 200.

***

### Tips

* **Use JSON format** (`?type=json_records`) — Zapier parses JSON fields automatically, making them available as individual fields in downstream steps.
* **Use `nest_json`** if your downstream app expects data under a specific key: `?type=json_records&nest_json=results`
* **Credit usage:** Each Zapier webhook call uses 1 credit. If your Zap runs hourly, that's \~720 credits/month.
* **SQL filtering:** Use the `sql` parameter to reduce the data to only what you need, keeping payloads small and Zapier steps fast.
* **Rate limits:** If running multiple Zaps against the same Airtable base, space them out to avoid Airtable's 5 req/sec limit.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.csvgetter.com/zapier-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
