# API v2 reference

**Base URL**: `https://parkdly.com/api/v2`

Every request needs an [app token](https://parkdly.com/docs/parkdly-api/v2-overview#authentication). Rate limits are the same as v1's [read limits](https://parkdly.com/docs/parkdly-api/rate-limits).

## List published courses

```
GET /api/v2/courses
```

Every course linked to your app that the club has published, a page at a time. A course linked but not yet published, or deleted, is left out.

| Query | What it does |
|---|---|
| `limit` | Courses per page: 1 to 100. Default 50. |
| `cursor` | Where the next page starts: the `nextCursor` of the page before. Leave it out for the first page. |

```json
{
  "courses": [ { "id": "clx123abc", "...": "a course object, below" } ],
  "nextCursor": "WzE3OTI0OTc2MDAwMDAsImNseG1hcDEiXQ"
}
```

`nextCursor` is `null` on the last page. Treat it as an opaque string: pass it back as it is.

Courses come in the order they were first linked to your app, oldest first. A course newly linked while you page comes at the end, so you don't miss it. A course that is published for the first time, restored from Recently deleted or reconnected while you page keeps its old place, so it may come only on your next pass; the [`course.published` webhook](https://parkdly.com/docs/parkdly-api/v2-overview#webhooks) tells you about it at once. A course whose links change while you page may come twice: match courses by `id`.

A page can be empty and still have a `nextCursor`: keep going until it is `null`.

```js
let cursor = null
do {
  const url = new URL('https://parkdly.com/api/v2/courses')
  url.searchParams.set('limit', '100')
  if (cursor) url.searchParams.set('cursor', cursor)
  const response = await fetch(url, { headers: { Authorization: `Bearer ${token}` } })
  if (!response.ok) throw new Error(`Parkdly answered ${response.status}`)
  const page = await response.json()
  for (const course of page.courses) save(course)
  cursor = page.nextCursor
} while (cursor)
```

A bad `limit` answers `400 invalid_limit`; a cursor this API did not give out answers `400 invalid_cursor`.

## Get a published course

```
GET /api/v2/courses/:courseId
```

`courseId` is the Parkdly course id. Answers a course object, or one of the [errors](https://parkdly.com/docs/parkdly-api/v2-overview#errors): `404 not_connected`, `409 not_published`, `410 course_deleted`.

## Connect a club's course

Your app never sees a list of the club's courses. You ask for one, and the club picks it on a Parkdly page.

**1. Start a connect session.** `POST /api/v2/connect-sessions`

```json
{ "externalCourseId": "your-course-id", "returnUrl": "https://yourapp.example/parkdly/back" }
```

`returnUrl` must be exactly one of your app's redirect URIs. The answer (`201`):

```json
{ "id": "k3Jd…", "url": "https://parkdly.com/connect/k3Jd…", "expiresAt": "2026-11-09T12:30:00.000Z" }
```

**2. Send the club to `url`.** There it logs in or signs up for free, picks one of its courses (or maps a new one) and the layouts you get, and confirms. Connecting publishes the course at once, so you have a version to read. A session lasts 30 minutes and works once.

**3. The club comes back** to `returnUrl?connect_session=<id>&status=connected` (or `status=canceled`). Don't trust the query string: read the session.

**4. Read the outcome.** `GET /api/v2/connect-sessions/:id`

```json
{
  "id": "k3Jd…",
  "status": "connected",
  "externalCourseId": "your-course-id",
  "courseId": "clx123abc",
  "layoutIds": ["clxlayout1"],
  "expiresAt": "2026-11-09T12:30:00.000Z"
}
```

`status` is `pending`, `connected`, `canceled` or `expired`. You also get a `course.connected` webhook.

**Moving a link.** Start a new session with the same `externalCourseId`. The club sees "Show another course in {your app}" and picks another course. Your `externalCourseId` stays; the course id changes. You get `course.disconnected` for the old course and `course.connected` for the new one. The old course stays in Parkdly with no link to you.

A course connects to your app once. The same course can be in several apps.

## Disconnect a course

`DELETE /api/v2/courses/:courseId/connection` → `{ "disconnected": true }`

Removes your link. The course stays in Parkdly; you read `not_connected` from now on and get `course.disconnected` with `by: "app"`. The club can disconnect too, from the course's Sharing tab. No link: `404 not_connected`.

## Course object

```json
{
  "id": "clx123abc",
  "externalCourseId": "your-course-id",
  "name": "Central Park DiscGolf",
  "studioUrl": "/studio/destinations/dst456/courses/clx123abc",
  "location": { "lat": 60.1699, "lng": 24.9384 },
  "version": { "number": 4, "publishedAt": "2026-10-30T12:00:00.000Z" },
  "layouts": [
    {
      "id": "lay789",
      "name": "Main",
      "isMain": true,
      "holes": [
        {
          "id": "hole001",
          "number": "1",
          "par": 3,
          "length": 85,
          "tee": { "lat": 60.17, "lng": 24.94 },
          "target": { "lat": 60.1708, "lng": 24.9412 },
          "flightPath": [{ "order": 0, "lat": 60.1704, "lng": 24.9406 }]
        }
      ]
    }
  ]
}
```

| Field | Type | Description |
|---|---|---|
| `id` | string | The Parkdly course id. The same in every version. |
| `externalCourseId` | string | Your id for the course, from when it was linked. |
| `name` | string | The course name, as published. |
| `studioUrl` | string | Path to the course in Parkdly Studio. |
| `location` | object \| null | The course location. |
| `version.number` | integer | Goes up by one with each publish. |
| `version.publishedAt` | string | When the club published this version (ISO 8601). |
| `layouts` | array | The layouts the club shares with your app. The main layout comes first. |

**Layout**

| Field | Type | Description |
|---|---|---|
| `id` | string | The layout id. The same in every version. |
| `name` | string | The layout name, as players see it. |
| `isMain` | boolean | The course's main layout. |
| `holes` | array | The holes the layout plays, in play order. |

**Hole**

| Field | Type | Description |
|---|---|---|
| `id` | string | The hole id. The same in every version and every layout. |
| `number` | string | The hole number on this layout, as players see it. A string, so don't do maths with it. |
| `par` | integer \| null | Par on this layout. |
| `length` | integer \| null | Length on this layout, in whole meters. |
| `tee` | object \| null | The tee this layout plays from. |
| `target` | object \| null | The target this layout plays to. |
| `flightPath` | array \| null | Control points of the hole's main flight path, in order. |
