114 lines
8.5 KiB
Markdown
114 lines
8.5 KiB
Markdown
# eventLabs API handoff for burnWorks
|
|
|
|
Connect the burnWorks Clubs workspace to eventLabs on WordPress. The burnWorks Worker owns the club's event data, authorization, and publishing rules. Use the persisted `club_events` row after the write in `worker/clubs.ts` so the request includes the generated ID and source timestamps.
|
|
|
|
## Connection
|
|
|
|
- In WordPress, create a dedicated user with the **eventLabs Integration** role. Generate a WordPress Application Password from that user's profile. The role grants access to the eventLabs API on that WordPress site.
|
|
- Store the WordPress URL, username, and Application Password in server-side connection settings or Worker secrets. Use HTTP Basic authentication with the username and Application Password. A deployed Worker needs a reachable HTTPS WordPress URL.
|
|
- API namespace is `eventlabs/v1`. Use `/wp-json/eventlabs/v1/…` on a site with REST rewrites, or set the `rest_route` query parameter to the full route. The query form also works with plain permalinks.
|
|
|
|
## Sync the club directory
|
|
|
|
After connecting a WordPress site, send the workspace's `clubs` records to `PUT /eventlabs/v1/burnworks/workspaces/{workspace_id}/clubs/{club_id}`. Use the UUIDs already stored by burnWorks. Repeat the PUT when a club's name, kind, or status changes.
|
|
|
|
```json
|
|
{
|
|
"name": "Young Gardeners",
|
|
"kind": "subclub",
|
|
"status": "active",
|
|
"workspace_name": "Field Club"
|
|
}
|
|
```
|
|
|
|
Use `clubs.kind` as `organization` or `subclub`, `clubs.status` as `active` or `archived`, and the workspace's display name as `workspace_name`. Read the directory with `GET /eventlabs/v1/burnworks/workspaces/{workspace_id}/clubs`. eventLabs stores the event's workspace and club IDs together in its hidden `sub_club` assignment. This keeps identical club IDs in different workspaces separate. The Elementor calendar and list can select a whole workspace or one club. Existing event sync requests still establish the association. The directory PUT gives that association its display name and kind.
|
|
|
|
## Publish a Clubs event
|
|
|
|
Send `PUT /eventlabs/v1/burnworks/workspaces/{workspace_id}/events/{event_id}` with a JSON object. Use the existing UUIDs from `club_events`. The same workspace and event IDs always resolve to the same WordPress record.
|
|
|
|
| burnWorks field | eventLabs mapping |
|
|
| --- | --- |
|
|
| `workspace_id`, `id` | External identity. Optional in the body when supplied in the route. |
|
|
| `club_id` | Club or sub-club association in the source record and the hidden event scope. |
|
|
| `title`, `description` | Source values plus a sanitized public title and description. |
|
|
| `starts_at` | Exact ISO 8601 value in the source record. The WordPress schedule uses UTC with second precision. |
|
|
| `venue` | Source venue name and the WordPress location field. |
|
|
| `status` | `draft`, `published`, or `cancelled`. A cancelled source event is withdrawn from the public calendar. |
|
|
| `audience` | `public`, `members`, or `private`. WordPress publishes the public audience only. |
|
|
| `capacity`, `kind` | Exact source values. Enforce membership, capacity, and waitlists in burnWorks. |
|
|
| `created_by`, `created_at` | Optional original creator and timestamp. Returned in the authenticated source record. |
|
|
| `ends_at` | Optional ISO 8601 end. The WordPress copy uses a one-hour duration when omitted. |
|
|
| `website_enabled`, `public_events_enabled` | Pass `club_sites.enabled` and the effective public events switch as JSON booleans. A missing switch counts as disabled. |
|
|
| `publish_to_wordpress` | Optional result of a burnWorks-specific rule. Send `false` to withdraw the WordPress copy. |
|
|
| `source_version` | Optional increasing integer from a durable per-event sequence. When supplied, later writes must carry a higher version or repeat the same version and payload. |
|
|
| `custom` | Optional JSON object for additional CRM fields. The API preserves nested JSON types and returns the object with the source record. |
|
|
|
|
WordPress publishes when the event is `published`, its audience is `public`, both website switches are `true`, and `publish_to_wordpress` is `true` or omitted. Other events are saved as drafts. Apply the same club and workspace authorization checks burnWorks uses for its existing event operations.
|
|
|
|
```ts
|
|
const route = `/eventlabs/v1/burnworks/workspaces/${event.workspace_id}/events/${event.id}`
|
|
const endpoint = new URL(connection.wordpressUrl)
|
|
endpoint.searchParams.set('rest_route', route)
|
|
|
|
const response = await fetch(endpoint, {
|
|
method: 'PUT',
|
|
redirect: 'error',
|
|
headers: {
|
|
Authorization: `Basic ${btoa(`${connection.username}:${connection.applicationPassword}`)}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
workspace_id: event.workspace_id,
|
|
id: event.id,
|
|
club_id: event.club_id,
|
|
title: event.title,
|
|
description: event.description,
|
|
starts_at: event.starts_at,
|
|
venue: event.venue,
|
|
status: event.status,
|
|
audience: event.audience,
|
|
capacity: event.capacity,
|
|
kind: event.kind,
|
|
created_by: event.created_by,
|
|
created_at: event.created_at,
|
|
website_enabled: Boolean(site?.enabled),
|
|
public_events_enabled: Boolean(site) && site?.public_events_enabled !== false && site?.public_events_enabled !== 0,
|
|
publish_to_wordpress: approvedForWebsite,
|
|
}),
|
|
})
|
|
if (!response.ok) {
|
|
const error = await response.json()
|
|
throw new Error(`eventLabs ${response.status}: ${error.code ?? 'request_failed'}`)
|
|
}
|
|
const saved = await response.json()
|
|
```
|
|
|
|
Here `event` is the saved Clubs event, `site` is its workspace's `club_sites` row if one exists, and `approvedForWebsite` is the boolean result of any additional CRM rules. Use `true` when the workspace has no additional rule. The public events switch follows the default used in `worker/club-platform.ts`.
|
|
|
|
## Sync behavior
|
|
|
|
- A successful PUT returns `201` on create and `200` on update. Save the returned WordPress `id`, `url_public`, and `revision` if the CRM needs them. The `burnworks` object is the last accepted source record. The other fields describe the current WordPress copy.
|
|
- Use GET on the same route to check the current state. Serialize writes per event and read the latest Clubs record when retrying. Use `source_version` for an outbox that can deliver writes out of order. Increment it for each distinct update, including changes to publishing rules, and resend the same payload on retry. A stale source version returns `409`. Use the returned `ETag` as `If-Match` when an update should fail if the WordPress copy changed since the last read. Re-read on `412`. A `503` indicates a busy record and can be retried. A `410` means the mapped WordPress record was permanently deleted.
|
|
- Re-send affected events when their audience, status, or publishing rules change, including site-level switches. Before deleting a source event, send a final PUT with `publish_to_wordpress: false` or retain a durable record of the withdrawal to retry it. Re-sending the same event after a withdrawal can publish it again.
|
|
- The WordPress credential is scoped to a site. The workspace UUID is an identity key. Enforce burnWorks workspace permissions in the Worker and keep connection credentials out of the browser.
|
|
|
|
## Direct eventLabs resources
|
|
|
|
Authenticated resource collections are `/events`, `/venues`, `/organizers`, and `/series` under `/eventlabs/v1`.
|
|
|
|
| Method and route | Purpose |
|
|
| --- | --- |
|
|
| `GET /schema` | Discover write fields, recurrence shape, CRM schema, and configured custom event fields. |
|
|
| `GET /{resource}` | List records. Follow `next_after_id` with `after_id`. Use `modified_since` for an inclusive time filter. |
|
|
| `POST /{resource}` | Create a native WordPress record. |
|
|
| `GET /{resource}/{id}` | Read the record with its ETag. |
|
|
| `PATCH /{resource}/{id}` | Change supplied fields. Use `If-Match` for conflict detection. |
|
|
| `GET, PUT /{resource}/external/{source}/{external_id}` | Read or upsert a stable record for another integration source. |
|
|
| `GET /events/{id}/occurrences` | Read indexed UTC occurrences. Follow `next_after_start` with `after_start`. |
|
|
| `GET /categories`, `GET /tags` | Resolve WordPress term IDs for the event's category and tag fields. |
|
|
|
|
Native event links use arrays of WordPress venue, organizer, and series IDs. The `fields` object follows the WordPress custom-field configuration. Venue and organizer coordinates are read-only API fields derived from the address. A changed address triggers a lookup when a Maps key is configured. Send `lookup_address: true` to retry it. A missing or ambiguous result has null coordinates and a status in `geocode`.
|
|
|
|
See the [API reference](API.md) for authentication examples, errors, and native payloads.
|