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

# Reports

> Export analytics as files instead of reading them page by page.

The report endpoints return the same data as a downloadable file. Use them for anything destined for a spreadsheet, a warehouse, or a scheduled email, rather than paginating through breakdowns and reassembling the result.

| Endpoint | Scope |
| - | - |
| `download_org_analytics_report_latest` | The whole organization |
| `download_campaign_analytics_report` | One campaign (`campaign_id`) |
| `download_shortlink_analytics_report_latest` | One link (`name`) |

```bash cURL theme={null}
curl -X GET "https://api.dashlink.ai/api/v1/analytics/download_org_analytics_report_latest?date_from=2026-01-01&date_to=2026-01-31&granularity=day" \
  -H "X-API-Key: $DASHLINK_API_KEY"
```

```javascript Node.js theme={null}
const response = await fetch("https://api.dashlink.ai/api/v1/analytics/download_org_analytics_report_latest?date_from=2026-01-01&date_to=2026-01-31&granularity=day", {
  headers: { "X-API-Key": process.env.DASHLINK_API_KEY },
});
const payload = await response.json();
```

```python Python theme={null}
import os
import requests

response = requests.get(
    'https://api.dashlink.ai/api/v1/analytics/download_org_analytics_report_latest?date_from=2026-01-01&date_to=2026-01-31&granularity=day',
    headers={'X-API-Key': os.environ["DASHLINK_API_KEY"]},
)
payload = response.json()
```

```go Go theme={null}
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	endpoint0 := "https://api.dashlink.ai/api/v1/analytics/download_org_analytics_report_latest?date_from=2026-01-01&date_to=2026-01-31&granularity=day"
	req0, err0 := http.NewRequest("GET", endpoint0, nil)
	if err0 != nil {
		panic(err0)
	}
	req0.Header.Set("X-API-Key", os.Getenv("DASHLINK_API_KEY"))
	resp0, err0b := http.DefaultClient.Do(req0)
	if err0b != nil {
		panic(err0b)
	}
	defer resp0.Body.Close()
	body0, _ := io.ReadAll(resp0.Body)
	fmt.Println(string(body0))
}

```

```ruby Ruby theme={null}
require "net/http"
require "json"
require "uri"

uri0 = URI("https://api.dashlink.ai/api/v1/analytics/download_org_analytics_report_latest?date_from=2026-01-01&date_to=2026-01-31&granularity=day")
request0 = Net::HTTP::Get.new(uri0)
request0["X-API-Key"] = ENV.fetch("DASHLINK_API_KEY")
response0 = Net::HTTP.start(uri0.hostname, uri0.port, use_ssl: true) do |http|
  http.request(request0)
end
payload0 = JSON.parse(response0.body)
```

```php PHP theme={null}
<?php
$ch0 = curl_init('https://api.dashlink.ai/api/v1/analytics/download_org_analytics_report_latest?date_from=2026-01-01&date_to=2026-01-31&granularity=day');
curl_setopt($ch0, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch0, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch0, CURLOPT_HTTPHEADER, [
    "X-API-Key: " . getenv("DASHLINK_API_KEY"),
]);
$payload0 = json_decode(curl_exec($ch0), true);
curl_close($ch0);
```

`date_from` and `date_to` are required. `granularity` and `metric` narrow what the report contains; the campaign report also accepts `timezone`.

> [!NOTE]
>
> These endpoints return a file, not the usual `{"data": ...}` envelope. Write the body to disk rather than parsing it as JSON — and if you get JSON back, that is an error envelope worth reading.

## A monthly export

```python theme={null}
import calendar
import requests
from datetime import date

def export_month(year, month, path):
    last = calendar.monthrange(year, month)[1]

    response = requests.get(
        f"{BASE}/analytics/download_org_analytics_report_latest",
        headers=HEADERS,
        params={
            "date_from": f"{year}-{month:02d}-01",
            "date_to": f"{year}-{month:02d}-{last}",
            "granularity": "day",
        },
    )

    if response.headers.get("content-type", "").startswith("application/json"):
        raise RuntimeError(response.json()["error"]["message"])

    with open(path, "wb") as handle:
        handle.write(response.content)
```

## Reports and retention

Reports read the same data as everything else, so the same [retention floor](https://docs.dashlink.ai/guides/analytics/retention.md) applies — and because you get a file rather than an envelope, there is no `retention` notice to warn you. A report for a range older than your window will simply start later than you asked.

Check the floor from `get_organization_plan_summary` before requesting a long historical export, and treat the first row of the file as the real start date.

## Practical notes

> [accordion] Export on a boundary
>
> Whole months or weeks concatenate cleanly. Overlapping ad-hoc ranges have to be de-duplicated by whoever inherits the spreadsheet.

> [accordion] Long ranges take time
>
> A wide export is real work. Allow a generous client timeout rather than retrying — a retry doubles the load and usually times out too.

> [accordion] Reports count against your rate limit
>
> They are ordinary requests. A nightly job exporting per-campaign reports across hundreds of campaigns needs the same pacing as any other loop. See [Rate limits](https://docs.dashlink.ai/guides/patterns/rate-limits.md).

> [accordion] Pass a timezone for the campaign report
>
> Day boundaries are UTC unless you say otherwise, which shifts every daily figure for a non-UTC audience.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.