# Export an entire event

Start an export job to download all participants for an event as an Excel workbook. For a specific set of leads, use the [selected participants example](/visitreport/reports/#export-participants-to-a-file).

## Queue a workbook

Find the [event ID](/visitreport/events/) and set it as `EVENT_ID`. Set `SNAPADDY_API_KEY` to a [personal API token](/authentication/) with dashboard access to that event and a role that can export all selected reports. An empty `participantIds` array with no `filter` selects all non-deleted participants in the event. The API checks access across that selection.

See the [API reference](/reference/job-management/) for the full request schema.

```bash
jq -n --arg event "$EVENT_ID" '{questionnaireId:$event, participantIds:[], downloadType:"EXCEL"}' |
  curl --fail-with-body 'https://backend.snapaddy.com/job-management/jobs/vr-download' \
    -H "x-api-key: $SNAPADDY_API_KEY" -H 'Content-Type: application/json' --data-binary @-
```

```typescript
const response = await fetch("https://backend.snapaddy.com/job-management/jobs/vr-download", {
  method: "POST",
  headers: { "x-api-key": process.env.SNAPADDY_API_KEY!, "Content-Type": "application/json" },
  body: JSON.stringify({ questionnaireId: process.env.EVENT_ID!, participantIds: [], downloadType: "EXCEL" }),
});
if (!response.ok) throw new Error(`Export request failed (${response.status})`);
console.log((await response.json()).id);
```

```python
import json, os
from urllib.request import Request, urlopen

body = {"questionnaireId": os.environ["EVENT_ID"], "participantIds": [], "downloadType": "EXCEL"}
request = Request("https://backend.snapaddy.com/job-management/jobs/vr-download",
                  data=json.dumps(body).encode(), method="POST",
                  headers={"x-api-key": os.environ["SNAPADDY_API_KEY"], "Content-Type": "application/json"})
with urlopen(request, timeout=20) as response:
    print(json.load(response)["id"])
```

A successful request returns `201`. Save its `id` as `JOB_ID`. If the selection is empty, the API returns `400` with `NO_PARTICIPANTS_FOUND`. Each successful submission queues a separate export.

## Wait for completion

Use [Poll a job](/platform/jobs/#poll-a-job) to read `GET /job-management/jobs/{id}`. Wait between requests and stop when the state reaches `completed`, `failed`, or `canceled`. If the job failed, inspect `failedReason`. Only a completed export has a downloadable result.

## Download the workbook

The result endpoint returns JSON containing a signed `url`. Use your API key for that first request. The signed URL supplies its own authorization for the second request.

```bash
url=$(curl --fail --silent --show-error \
  "https://backend.snapaddy.com/job-management/jobs/vr-download/$JOB_ID/result" \
  -H "x-api-key: $SNAPADDY_API_KEY" | jq -er '.url') &&
  curl --fail --output event.xlsx "$url"
```

```typescript
import { writeFile } from "node:fs/promises";

const result = await fetch(`https://backend.snapaddy.com/job-management/jobs/vr-download/${process.env.JOB_ID}/result`, {
  headers: { "x-api-key": process.env.SNAPADDY_API_KEY! },
});
if (!result.ok) throw new Error(`Result lookup failed (${result.status})`);
const { url } = await result.json();
const file = await fetch(url);
if (!file.ok) throw new Error(`Download failed (${file.status})`);
await writeFile("event.xlsx", new Uint8Array(await file.arrayBuffer()));
```

```python
import json, os, shutil
from urllib.request import Request, urlopen

url = f"https://backend.snapaddy.com/job-management/jobs/vr-download/{os.environ['JOB_ID']}/result"
request = Request(url, headers={"x-api-key": os.environ["SNAPADDY_API_KEY"]})
with urlopen(request, timeout=20) as response:
    download_url = json.load(response)["url"]
with urlopen(download_url, timeout=60) as response, open("event.xlsx", "wb") as file:
    shutil.copyfileobj(response, file)
```

A result lookup can return `404` for an unknown or unfinished job. Results expire 30 days after completion, when lookup returns `410`. To generate other file formats, see the [export API reference](/reference/job-management/).
