> ## 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.

# Joining form on your website

> Send each answer to your own joining form straight onto your waiting list, with no copying and pasting. Google Forms or Microsoft Forms.

> [!NOTE]
>
> * **For:** group admins with a joining form on their website
> * **You get:** each answer to your Google Form or Microsoft Form added to your waiting list
> * **Time:** about fifteen minutes
> * **Scopes:** `waiting-list:read`, `waiting-list.contacts:read` and `waiting-list:write`

Many groups have a joining form on their own website: a Google Form or a Microsoft Form. Someone then copies each answer into Scoutworks by hand. This recipe sends each answer straight onto your **waiting list** instead. It takes about fifteen minutes.

It is for a **group admin**. The form asks the same questions as the Scoutworks waiting-list form, and the API checks them by the same rules.

## 1. Create a key

In Scoutworks, open **Settings → Integrations → API keys** and create a key called **Joining form**, with the scopes **`waiting-list:read`**, **`waiting-list.contacts:read`** and **`waiting-list:write`**. Copy the key: you see it once. See [Authentication](https://developers.scoutworks.app/guides/authentication.md).

The form adds applications as you, and Scoutworks records the key on each one. Leaders who follow the waiting list are told in Scoutworks, as for every application. **The family is not emailed** unless you choose to below.

## 2. Make the form

Ask these questions. The names in brackets are the fields the script sends.

| Question | Type | Field |
| - | - | - |
| Child's first name | Short answer, required | `childFirstName` |
| Child's last name | Short answer, required | `childLastName` |
| Child's date of birth | Date, required | `childDateOfBirth` |
| Your first name | Short answer, required | `parentFirstName` |
| Your last name | Short answer, required | `parentLastName` |
| Your email | Short answer, required, email validation | `parentEmail` |
| Your phone number | Short answer, required | `parentPhone` |
| Address line 1 | Short answer, required | `addressLine1` |
| Town or city | Short answer, required | `city` |
| Postcode | Short answer, required | `postcode` |
| Anything we should know? | Paragraph | `specialInformation` |

Keep the question titles exactly as in the first column, because the script looks for them.

## 3. Google Forms: add the script

**1. Open the form's script editor**

In the form, choose **⋮ → Script editor**. Delete what is there, paste the script below and choose **Save**.

**2. Add your key**

Choose **Project Settings → Script Properties → Add script property**. **Property:** `SCOUTWORKS_API_KEY`. **Value:** your key. The key is stored with the script, not in the form, so people filling it in never see it.

**3. Run it on every answer**

Choose **Triggers → Add Trigger**. Function: `sendToWaitingList`. Event source: **From form**. Event type: **On form submit**. Google asks you to allow the script to read the form and connect to an external service.

```javascript Code.gs theme={null}
// Joining form → Scoutworks waiting list.
// https://developers.scoutworks.app/recipes/joining-form

const FIELDS = {
  "Child's first name": 'childFirstName',
  "Child's last name": 'childLastName',
  "Child's date of birth": 'childDateOfBirth',
  'Your first name': 'parentFirstName',
  'Your last name': 'parentLastName',
  'Your email': 'parentEmail',
  'Your phone number': 'parentPhone',
  'Address line 1': 'addressLine1',
  'Town or city': 'city',
  Postcode: 'postcode',
  'Anything we should know?': 'specialInformation',
};

function sendToWaitingList(e) {
  const apiKey = PropertiesService.getScriptProperties().getProperty('SCOUTWORKS_API_KEY');
  const body = {};
  e.response.getItemResponses().forEach(function (answer) {
    const field = FIELDS[answer.getItem().getTitle()];
    const value = String(answer.getResponse()).trim();
    if (field && value) body[field] = value;
  });

  const res = UrlFetchApp.fetch('https://api.scoutworks.app/api/v1/waiting-list', {
    method: 'post',
    contentType: 'application/json',
    headers: {
      Authorization: 'Bearer ' + apiKey,
      // The answer's own id: if Google runs the script twice for one answer,
      // Scoutworks still adds one application.
      'Idempotency-Key': 'google-form-' + e.response.getId(),
    },
    payload: JSON.stringify(body),
    muteHttpExceptions: true,
  });

  const status = res.getResponseCode();
  if (status === 201 || status === 200) return;
  const error = JSON.parse(res.getContentText()).error;
  if (error.code === 'possible_duplicate') {
    console.log('Already on the waiting list: ' + body.childFirstName + ' ' + body.childLastName);
    return;
  }
  // Shows in Executions, and Google emails you a failure summary.
  throw new Error(status + ' ' + error.code + ': ' + error.message);
}
```

Fill in the form once yourself, with a made-up child, to test it. The application appears on your waiting list in Scoutworks within a few seconds. Delete it there when you have checked it.

## 4. Microsoft Forms: use Power Automate instead

Power Automate's **HTTP** action needs a premium licence. If you have one:

**1. Start the flow**

Create an **Automated cloud flow** with the trigger **When a new response is submitted** (Microsoft Forms), then **Get response details**.

**2. Add an HTTP action**

* **Method:** POST
* **URI:** `https://api.scoutworks.app/api/v1/waiting-list`
* **Headers:** `Authorization` = `Bearer ` followed by your key, `Content-Type` = `application/json`, and `Idempotency-Key` = `ms-form-` followed by the **Response Id** from the trigger
* **Body:** a JSON object with the fields in the table above, each set to the matching answer from **Get response details**

**3. Test it**

Fill in the form once with a made-up child, check the flow's run history, then delete the application in Scoutworks.

Keep the key in an environment variable or Azure Key Vault rather than typed into the action, if your organisation has one.

## Choices

* **Send the family the confirmation email.** Add `"notify": true` to the body. The family then gets the same confirmation the Scoutworks form sends. Leave it out while you test.
* **A section to wait for.** Add `targetSectionId` with a section's `id` from [`GET /sections`](https://developers.scoutworks.app/api-reference/introduction), or let leaders choose one in Scoutworks.
* **Siblings and preferred days.** The API also takes `hasSibling`, `siblingName`, `preferredDays` and `willingToVolunteer`. The [API reference](https://developers.scoutworks.app/api-reference/introduction.md) lists every field.

## If something goes wrong

* **`400 invalid_request`**: an answer did not pass the form's rules, for example a phone number that is not a UK number or a child over 18. The message names the field.
* **`403 insufficient_scope`**: the key needs all three waiting-list scopes.
* **`409 possible_duplicate`**: the child is on the waiting list already. The script logs it and stops.
* **`402 subscription_required`**: the group's subscription has lapsed.

See [Errors](https://developers.scoutworks.app/guides/errors.md) for every code.


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