# API v2

**Status**: Preview. Parkdly turns API v2 on for each app: ask us to enable it for yours.

API v2 serves the version of a course the club **published**, not the course as it is being edited. A club can work on its course for weeks; your app sees the change only when the club presses **Publish**. Each publish is a new version with a number: 1, 2, 3, and so on.

[API v1](https://parkdly.com/docs/parkdly-api/endpoints) does not change. It keeps the same answers and still reads the live course.

## Authentication

API v2 uses one token for your app, not one per club. Ask for it with your app's credentials:

```
POST https://parkdly.com/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}
```

```json
{
  "access_token": "eyJhbGciOi...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "read"
}
```

Send it on every request, and ask for a new one when it expires:

```
Authorization: Bearer {access_token}
```

With this token, a club's link to your app is the permission: you read every course a club has linked to your app. A user's v1 token does not work on v2, and the app token does not work on v1.

An app that Parkdly has not turned v2 on for gets `400 unauthorized_client`.

## Versions

- Your app reads the **last published version** of a course. Edits after it reach your app only with the next publish.
- Each version has a `number` that only goes up, and a `publishedAt` time. Store the number: when a webhook brings a higher one, read the course again.
- **Ids stay the same across versions.** A course, layout or hole keeps its id from one version to the next, so you can match them with what you stored. A hole deleted after a publish keeps its id in v2 until the club publishes again.
- You get the layouts the club shares with your app, each with its own hole numbers, par and length.

## Errors

Errors have the same format as in v1: `{ "error": "<code>", "message": "..." }`. Your app can tell these apart:

| Status | `error` | What it means |
|---|---|---|
| `401` | `unauthorized` | No app token, an expired one, or a user's v1 token. |
| `404` | `not_connected` | The course is not linked to your app, or the club disconnected your app. |
| `409` | `not_published` | The course is linked to your app, but the club has not published it yet. |
| `410` | `course_deleted` | The club deleted the course. It can still restore it for 30 days. After that the course answers `404`. |
| `400` | `invalid_limit` | `limit` is not a whole number from 1 to 100. |
| `400` | `invalid_cursor` | `cursor` is not a `nextCursor` this API gave out. |
| `400` | `invalid_request` | The request body is not valid JSON, or a field is missing. |
| `400` | `invalid_return_url` | `returnUrl` is not exactly one of your app's redirect URIs. |
| `404` | `session_not_found` | No connect session with that id for your app. |
| `429` | `rate_limit_exceeded` | See [Rate Limits](https://parkdly.com/docs/parkdly-api/rate-limits). |

## Webhooks

For an app on API v2, `course.published` carries the version, not the course. Read the course with `GET /api/v2/courses/:courseId`.

```json
{
  "event": "course.published",
  "timestamp": "2026-11-09T12:00:00.000Z",
  "courseId": "clx123abc",
  "externalCourseId": "your-course-id",
  "version": { "number": 4, "publishedAt": "2026-11-09T12:00:00.000Z" }
}
```

`course.deleted` carries no course either, so you never see edits the club did not publish:

```json
{
  "event": "course.deleted",
  "timestamp": "2026-11-09T12:00:00.000Z",
  "courseId": "clx123abc",
  "externalCourseId": "your-course-id"
}
```

`course.connected` tells you which course the club connected, or moved your link to. `version` is `null` for a new course the club still has to map; you get `course.published` once it publishes.

```json
{
  "event": "course.connected",
  "timestamp": "2026-11-09T12:00:00.000Z",
  "courseId": "clx123abc",
  "externalCourseId": "your-course-id",
  "layoutIds": ["clxlayout1"],
  "version": { "number": 1, "publishedAt": "2026-11-09T12:00:00.000Z" }
}
```

`course.disconnected` says the link is gone; the course reads `not_connected` from now on. `by` is `club` or `app`. When the club moves your link to another course, you get `course.disconnected` for the old course and `course.connected` for the new one, with the same `externalCourseId`.

```json
{
  "event": "course.disconnected",
  "timestamp": "2026-11-09T12:00:00.000Z",
  "courseId": "clx123abc",
  "externalCourseId": "your-course-id",
  "by": "club"
}
```

Headers, signatures, retries and when `course.deleted` is sent are as in [Webhooks](https://parkdly.com/docs/parkdly-api/webhooks).

## Next Steps

- [API v2 reference](https://parkdly.com/docs/parkdly-api/v2-reference): the endpoints and the course object.
