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

# Move money between your accounts

> Record a transfer you have made, such as savings to current, from a Google Sheet or a phone shortcut. Both sides land in the books at once.

> [!NOTE]
>
> * **For:** treasurers
> * **You get:** a transfer between two of your own accounts recorded in Scoutworks, both sides at once, from a sheet row or a shortcut on your phone
> * **Time:** about fifteen minutes
> * **Scopes:** `accounting:read` and `accounting:write`

You moved £500 from savings to the current account for camp. In Scoutworks that is one transfer with two sides: money out of savings and into current. This recipe records it from a Google Sheet, or from a phone shortcut while you are still in the banking app. Nothing moves in the bank: it records a transfer you have already made.

> [!WARNING]
>
> This recipe changes your books, so the read-only [sandbox key](https://developers.scoutworks.app/guides/sandbox.md) cannot run it. Use your own key with `accounting:write`, and [try it on one made-up transfer](#4-try-it-on-one-transfer) first.

## 1. Create a key and find your accounts

A group admin creates a key in **Settings → Integrations → API keys** with **`accounting:read`** and **`accounting:write`**. A transfer the key records shows that admin as the person who added it, and Scoutworks marks it as added by the key.

List your accounts to find their ids. Try it on the demo group first:

```bash theme={null}
curl "https://api-demo.scoutworks.app/api/v1/bank-accounts?limit=200" \
  -H "Authorization: Bearer sw_test_473adcc6c7236916021f0f24559db36576a53bab071d0f0c08a025adb510b6ab"
```

With your own key, call `https://api.scoutworks.app/api/v1/bank-accounts` and copy the `id` of each account you move money between.

## 2. Lay out the sheet

Make a tab called **Transfers**. Row 1 holds headings. From row 2, one transfer a row:

| Column | Holds | Example |
| - | - | - |
| A | The day it left, as `DD/MM/YYYY` | `14/11/2026` |
| B | The account it left: its `id` | `0b5c…` |
| C | The account it arrived in: its `id` | `9e21…` |
| D | The amount, in pounds | `500.00` |
| E | What it was for | `Savings to current for camp` |
| F | Leave empty. The script writes the transfer's id here. | |
| G | Leave empty. The script writes any problem here. | |
| H | Leave empty. The script keeps the row's `Idempotency-Key` here. | |

Format column A as **Format → Number → Plain text** before you type, so a date is always read as day, month, year.

## 3. Add the script

Choose **Extensions → Apps Script**. Delete what is there, paste the script below and choose **Save**. Then add a script property `SCOUTWORKS_API_KEY` with your key, in **Project Settings → Script Properties**.

```javascript Code.gs theme={null}
// Scoutworks → record transfers between your accounts. https://developers.scoutworks.app/recipes/move-money

const BASE = 'https://api.scoutworks.app/api/v1';

function recordTransfers() {
  const apiKey = PropertiesService.getScriptProperties().getProperty('SCOUTWORKS_API_KEY');
  if (!apiKey) throw new Error('Add SCOUTWORKS_API_KEY in Project Settings → Script Properties.');
  const sheet = SpreadsheetApp.getActive().getSheetByName('Transfers');
  const rows = sheet.getDataRange().getValues();
  let added = 0;

  for (let i = 1; i < rows.length; i++) {
    const [date, from, to, amount, what, id, , sent] = rows[i];
    if (id || date === '' || !from || !to || !amount) continue; // Done, or not filled in.
    const m = String(date).match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
    if (!m) { sheet.getRange(i + 1, 7).setValue('Use DD/MM/YYYY for the date.'); continue; }
    const day = m[3] + '-' + ('0' + m[2]).slice(-2) + '-' + ('0' + m[1]).slice(-2);
    const pounds = Number(amount).toFixed(2);

    // One key per row, kept in column H: a retry of the row sends it again, so
    // it is never recorded twice, while two identical transfers stay two.
    const key = sent || 'transfer-' + Utilities.getUuid();
    sheet.getRange(i + 1, 8).setValue(key);
    const res = UrlFetchApp.fetch(BASE + '/transfers', {
      method: 'post',
      contentType: 'application/json',
      headers: { Authorization: 'Bearer ' + apiKey, 'Idempotency-Key': key },
      payload: JSON.stringify({
        fromBankAccountId: from,
        toBankAccountId: to,
        amount: pounds,
        date: day,
        description: String(what || 'Transfer between accounts').slice(0, 500),
      }),
      muteHttpExceptions: true,
    });
    const body = JSON.parse(res.getContentText());
    if (res.getResponseCode() === 200 || res.getResponseCode() === 201) {
      sheet.getRange(i + 1, 6, 1, 2).setValues([[body.data.id, '']]);
      added++;
    } else {
      sheet.getRange(i + 1, 7).setValue(body.error.code + ': ' + body.error.message);
    }
    Utilities.sleep(2100); // Stay under 30 changes a minute.
  }
  SpreadsheetApp.getActive().toast(added + ' transfers recorded.');
}

```

## 4. Try it on one transfer

**1. Add one made-up transfer**

One row: today's date, your two account ids, `0.01`, and `TEST from the Scoutworks recipe`.

**2. Run it**

Choose **recordTransfers** and press **Run**. The first time, Google asks you to allow the script to reach an outside service. Column F gets an id that starts `transfer_`.

**3. Check it in Scoutworks**

Open **Finance → Transactions**. The test shows twice: 1p out of the first account and 1p into the second, both marked as a transfer.

**4. Undo it**

Delete the transfer in Scoutworks, which deletes both sides, or send `DELETE /transfers/{id}` with the id from column F. Then delete the test row.

## 5. Run it

Add a row for each transfer and choose **Run**. A row that already has an id is skipped, so you can keep one running list.

## From your phone

An iPhone **Shortcut** can record a transfer while you are still in the banking app. Make a shortcut with **Ask for Input** (a number: the amount), then **Get Contents of URL**:

* **URL:** `https://api.scoutworks.app/api/v1/transfers`
* **Method:** `POST`
* **Headers:** `Authorization` = `Bearer ` and your key; `Idempotency-Key` = the **Current Date** formatted as `yyyyMMddHHmm` and the amount, so pressing it twice in the same minute records one transfer.
* **Request Body:** JSON, with `fromBankAccountId` and `toBankAccountId` typed in once, `amount` from the input (with two decimal places, for example `500.00`), `date` as **Current Date** formatted `yyyy-MM-dd`, and `description`.

Keep the key only in the shortcut, on a phone with a passcode. Anyone with the shortcut can add to your books.

## Changing or deleting one

`PATCH /transfers/{id}` changes the amount, dates, description or reference of both sides together, and `DELETE /transfers/{id}` deletes both. Each works only on a transfer the API recorded, whose sides are not yet matched to a bank statement: anything else answers `409 source_locked`, so change it in Scoutworks. Send the `ETag` you last read as `If-Match`; if the transfer changed since, the answer is `412 stale_write` and nothing changes.

## If something goes wrong

* **`400 invalid_request`**: usually an account id that is wrong, closed or not your group's, or the same account twice. The message says which.
* **`409 period_closed`**: the date is in an accounting year that is closed.
* **`403 insufficient_scope`**: the key needs `accounting:read` and `accounting:write`.
* **The arriving side has a different date** on its statement: send `destinationDate` too, up to 7 days after `date`.

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.