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

# Hall bookings in your calendar

> Your hall, pitch and equipment bookings, and the dates you have blocked, as a calendar feed your lettings secretary and caretaker subscribe to. For lettings secretaries.

> [!NOTE]
>
> * **For:** group admins and whoever runs lettings
> * **You get:** a calendar feed of hire bookings and blocked dates for your phone or Outlook
> * **Time:** about fifteen minutes
> * **Scopes:** `hire:read`

This recipe turns your hire bookings into a calendar feed. Your lettings secretary, caretaker and leaders subscribe to it once. When a booking is added, confirmed or cancelled in Scoutworks, their calendar follows on its own. Dates you have blocked show too, so nobody promises the hall on a night it is closed.

It works the same way as [Events in your calendar](https://developers.scoutworks.app/recipes/calendar-feed.md): a free Google Apps Script web app. It takes about ten minutes.

## 1. Add the script

**1. Create a project**

Go to [script.google.com](https://script.google.com) and choose **New project**. Call it **Scoutworks hire calendar**.

**2. Paste the script**

Delete what is there and paste the script below. Choose **Save**.

```javascript Code.gs theme={null}
// Scoutworks → hire calendar feed. https://developers.scoutworks.app/recipes/hall-lettings-calendar

const BASE = 'https://api-demo.scoutworks.app/api/v1';
const DAY = 24 * 60 * 60 * 1000;

// Calendar apps call this address. Add ?asset=main-hall for one thing only.
function doGet(e) {
  const only = ((e && e.parameter && e.parameter.asset) || '').toLowerCase().slice(0, 80);

  // Serve a copy made in the last hour. Repeated requests then cost no API calls.
  const cache = CacheService.getScriptCache();
  const cached = cache.get('hire:' + only);
  if (cached) return ContentService.createTextOutput(cached).setMimeType(ContentService.MimeType.ICAL);

  const now = new Date();
  const from = new Date(now.getTime() - 30 * DAY).toISOString();

  const group = fetchScoutworks(BASE + '/me').data.group.name;
  const assets = new Map();
  readAll('/hire-assets').forEach(function (a) { assets.set(a.id, a); });
  const wanted = function (assetId) {
    if (!only) return true;
    const asset = assets.get(assetId);
    return asset ? asset.slug === only : false;
  };

  const lines = [
    'BEGIN:VCALENDAR',
    'VERSION:2.0',
    'PRODID:-//Scoutworks hire calendar recipe//EN',
    'CALSCALE:GREGORIAN',
    'METHOD:PUBLISH',
    'X-WR-CALNAME:' + text(group + ' bookings'),
  ];

  readAll('/hire-bookings').forEach(function (b) {
    if (b.status === 'cancelled' || b.endAt < from || !wanted(b.assetId)) return;
    const asset = assets.get(b.assetId);
    const who = b.hirerType === 'private' || !b.organisationName ? HIRERS[b.hirerType] || 'Hire' : b.organisationName;
    lines.push(
      'BEGIN:VEVENT',
      'UID:' + b.id + '@scoutworks.app',
      'DTSTAMP:' + stamp(now),
      'DTSTART:' + stamp(new Date(b.startAt)),
      'DTEND:' + stamp(new Date(b.endAt)),
      'SUMMARY:' + text((b.status === 'pending' ? 'Provisional: ' : '') + who),
      'LOCATION:' + text(asset ? asset.name : ''),
      'DESCRIPTION:' + text('Booking ' + b.reference + '. ' + STATUSES[b.status] +
        (b.expectedAttendees ? '. About ' + b.expectedAttendees + ' people' : '') + '.'),
      'STATUS:' + (b.status === 'pending' ? 'TENTATIVE' : 'CONFIRMED'),
      'END:VEVENT'
    );
  });

  readAll('/hire-blocked-dates').forEach(function (d) {
    // A block with no asset covers everything you hire out.
    if (d.endAt < from || (d.assetId !== null && !wanted(d.assetId))) return;
    const asset = d.assetId ? assets.get(d.assetId) : null;
    lines.push(
      'BEGIN:VEVENT',
      'UID:' + d.id + '@blocked.scoutworks.app',
      'DTSTAMP:' + stamp(now),
      'DTSTART:' + stamp(new Date(d.startAt)),
      'DTEND:' + stamp(new Date(d.endAt)),
      'SUMMARY:' + text('Not available: ' + (asset ? asset.name : 'everything')),
      'TRANSP:OPAQUE',
      'END:VEVENT'
    );
  });
  lines.push('END:VCALENDAR');

  const ics = lines.map(fold).join('\r\n') + '\r\n';
  try {
    cache.put('hire:' + only, ics, 60 * 60);
  } catch (err) {
    // A feed over 100 KB is too big to keep. Serve it without the copy.
  }
  return ContentService.createTextOutput(ics).setMimeType(ContentService.MimeType.ICAL);
}

const STATUSES = {
  pending: 'Waiting for you to confirm',
  confirmed: 'Confirmed',
  awaiting_inspection: 'Ended, to be checked',
  completed: 'Completed',
};

const HIRERS = {
  scout_group: 'Scout group',
  community: 'Community group',
  private: 'Private hire',
  corporate: 'Business',
  other: 'Hire',
};

// 2026-09-24T18:30:00.000Z → 20260924T183000Z
function stamp(date) {
  return date.toISOString().replace(/[-:]/g, '').replace(/\.\d{3}/, '');
}

// Escapes the characters that have a meaning in a calendar file.
function text(value) {
  return String(value)
    .replace(/\\/g, '\\\\')
    .replace(/;/g, '\\;')
    .replace(/,/g, '\\,')
    .replace(/\r?\n/g, '\\n');
}

// Calendar files keep each line short. A long line continues after a space.
function fold(line) {
  const parts = [];
  while (line.length > 73) {
    parts.push(line.slice(0, 73));
    line = ' ' + line.slice(73);
  }
  parts.push(line);
  return parts.join('\r\n');
}

// Every item in a list, following nextCursor to the last page.
function readAll(path) {
  const items = [];
  let cursor = null;
  do {
    let url = BASE + path + (path.indexOf('?') === -1 ? '?' : '&') + 'limit=200';
    if (cursor) url += '&cursor=' + encodeURIComponent(cursor);
    const body = fetchScoutworks(url);
    items.push.apply(items, body.data);
    cursor = body.nextCursor;
  } while (cursor);
  return items;
}

// Calls the API. Waits and tries again if the rate limit is reached.
function fetchScoutworks(url) {
  const apiKey = PropertiesService.getScriptProperties().getProperty('SCOUTWORKS_API_KEY');
  if (!apiKey) throw new Error('Add SCOUTWORKS_API_KEY in Project Settings → Script Properties.');
  for (let attempt = 0; attempt < 3; attempt++) {
    const res = UrlFetchApp.fetch(url, {
      headers: { Authorization: 'Bearer ' + apiKey },
      muteHttpExceptions: true,
    });
    const body = JSON.parse(res.getContentText());
    if (res.getResponseCode() === 200) return body;
    if (res.getResponseCode() === 429) {
      Utilities.sleep((body.retryAfter || 30) * 1000);
      continue;
    }
    throw new Error(body.error.code + ': ' + body.error.message);
  }
  throw new Error('Scoutworks is still busy. Try again in a minute.');
}
```

## 2. Add your key

In the script editor, choose **Project Settings** (the cog), then **Script Properties → Add script property**. Property: `SCOUTWORKS_API_KEY`. Value: the [sandbox key](https://developers.scoutworks.app/guides/sandbox.md) to try it, or your own key. Choose **Save script properties**.

## 3. Publish it and subscribe

Publish the script as a web app and subscribe to its address, exactly as in [Events in your calendar](https://developers.scoutworks.app/recipes/calendar-feed.md#3-publish-it-as-a-web-app): **Deploy → New deployment → Web app**, **Execute as: Me**, **Who has access: Anyone**. Then add the **Web app URL** to Google Calendar, Outlook or Apple Calendar as a subscribed calendar.

For one thing you hire out, add `?asset=` and its web address name to the end of the address, for example `…/exec?asset=main-hall`. The name is the last part of the thing's address on your public hire page. Dates you block for everything show in every feed.

## 4. Switch to your group

In the script, change `api-demo.scoutworks.app` to `api.scoutworks.app`. In Script Properties, replace the sandbox key with your own. Your key needs the `hire:read` scope. **Give it no other scope**, and never `hire.people:read`.

After you change the script, choose **Deploy → Manage deployments → Edit** (the pencil), set **Version** to **New version** and choose **Deploy**. The address stays the same.

> [!WARNING]
>
> Anyone with the address can see when your hall is booked and by which organisation. The feed never holds a hirer's name, email or phone number, and a private hirer shows only as **Private hire**. Keep it that way: a key with only `hire:read` cannot read contact details, even if someone edits the script. Share the address only with the people who run your lettings.

## Notes

* The feed holds bookings and blocked dates from 30 days ago onwards. Cancelled bookings are left out.
* A booking still **pending** shows as **Provisional**, and as tentative in calendars that show it.
* The script keeps each feed for **one hour**, so a change in Scoutworks reaches the feed within an hour. Calendar apps then check on their own timetable, often every few hours.
* Each booking keeps its Scoutworks ID in the calendar, so a moved booking moves in the calendar. It does not appear twice.
* The reason for a blocked date never leaves Scoutworks. The feed shows only **Not available**.


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