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

# Gift Aid tax year check

> Before you send a Gift Aid claim to HMRC, check it line by line: the totals for the tax year and every claim line, in a Google Sheet.

> [!NOTE]
>
> * **For:** treasurers and Gift Aid officers
> * **You get:** a **Gift Aid** tab with the year's totals and a **Claim lines** tab with every line, to check against the HMRC schedule
> * **Time:** about ten minutes
> * **Scopes:** `gift-aid:read`, and `gift-aid.people:read` for donor names and postcodes

A Gift Aid claim is only as good as its lines. This recipe puts a tax year's claim in a Google Sheet, so a second person can check it before it goes to HMRC. The totals come from the same calculation as the **Export Gift Aid Report** option on the **Finance** page in Scoutworks, so they match it to the penny.

## 1. Try the requests

A UK tax year is written `YYYY-YY`: `2025-26` runs from 6 April 2025 to 5 April 2026. Paste these into a terminal to see the demo group's figures:

```bash theme={null}
curl "https://api-demo.scoutworks.app/api/v1/gift-aid/summary?taxYear=2025-26" \
  -H "Authorization: Bearer sw_test_473adcc6c7236916021f0f24559db36576a53bab071d0f0c08a025adb510b6ab"

curl "https://api-demo.scoutworks.app/api/v1/gift-aid/claim-lines?taxYear=2025-26&limit=200" \
  -H "Authorization: Bearer sw_test_473adcc6c7236916021f0f24559db36576a53bab071d0f0c08a025adb510b6ab"
```

The summary splits the claim three ways:

* **`declaration`**: donations from people who signed a Gift Aid declaration. These go on the HMRC schedule with the donor's name and postcode.
* **`gasds`**: small cash donations under the Gift Aid Small Donations Scheme. HMRC needs only the total.
* **`manual`**: donations the treasurer marked as eligible by hand.

## 2. Add the script

In your Google Sheet, choose **Extensions → Apps Script**. Delete what is there, paste the script below and choose **Save**.

```javascript Code.gs theme={null}
// Scoutworks → Gift Aid tax year check. https://developers.scoutworks.app/recipes/gift-aid-check

const BASE = 'https://api-demo.scoutworks.app/api/v1';
const TAX_YEAR = '2025-26'; // The year you are about to claim for.

const TYPES = { declaration: 'Declaration', gasds: 'Small donations (GASDS)', manual: 'Marked by hand' };

function giftAidCheck() {
  const s = fetchScoutworks(BASE + '/gift-aid/summary?taxYear=' + TAX_YEAR).data;
  const summary = [
    ['Tax year', s.taxYear + ' (' + s.startDate.slice(0, 10) + ' to ' + s.endDate.slice(0, 10) + ')', '', ''],
    ['', 'Donations (£)', 'Gift Aid due (£)', 'Lines'],
  ];
  Object.keys(TYPES).forEach(function (type) {
    const t = s.byType[type];
    summary.push([TYPES[type], Number(t.donationsTotal), Number(t.giftAidDue), t.lineCount]);
  });
  summary.push(['Total', Number(s.donationsTotal), Number(s.giftAidDue), s.lineCount]);
  summary.push(['Left out because not yet reconciled', '', '', s.excludedUnreconciledCount]);
  writeTab('Gift Aid', summary);

  const all = readAll('/gift-aid/claim-lines?taxYear=' + TAX_YEAR);
  // Donor details come only with gift-aid.people:read. Without them, don't flag every line.
  const hasDonors = all.some(function (l) { return l.donorName; });
  const lines = all
    .sort(function (a, b) { return a.type.localeCompare(b.type) || a.date.localeCompare(b.date); })
    .map(function (l) {
      return [
        l.date.slice(0, 10),
        TYPES[l.type],
        Number(l.amount),
        safe(l.donorName || ''),
        safe(l.donorAddressLine1 || ''),
        safe(l.donorPostcode || ''),
        hasDonors && l.type === 'declaration' && !l.donorPostcode ? 'No postcode' : '',
      ];
    });
  writeTab('Claim lines', [['Date', 'Kind', 'Donation (£)', 'Donor', 'Address', 'Postcode', 'Check']].concat(lines));

  SpreadsheetApp.getActive().toast(
    s.lineCount + ' lines, £' + s.giftAidDue + ' Gift Aid due.' + (s.truncated ? ' Too many donations for one claim: the figures are too low.' : '')
  );
}

// Replaces a tab's contents with these rows.
function writeTab(name, rows) {
  const book = SpreadsheetApp.getActive();
  const sheet = book.getSheetByName(name) || book.insertSheet(name);
  sheet.clearContents();
  sheet.getRange(1, 1, rows.length, rows[0].length).setValues(rows);
  sheet.setFrozenRows(1);
}

// 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.');
}

// Stops text that starts with = + - or @ from running as a formula.
function safe(value) {
  const text = String(value);
  return /^\s*[=+\-@]/.test(text) ? "'" + text : text;
}
```

## 3. Add your key and run it

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. Then choose **giftAidCheck** and press **Run**.

## 4. Check it against the HMRC schedule

In Scoutworks, open **Finance**, choose **Export Gift Aid Report** for the same dates, and download the HMRC schedule. Then check:

1. **The totals match.** The **Declaration** donations on the **Gift Aid** tab equal the schedule's total. The **Small donations** total is the figure for the GASDS part of the claim.
2. **Every declaration line has a donor and a postcode.** HMRC rejects a line without them. The **Check** column flags any that are missing. It needs `gift-aid.people:read`: without it, every donor column is empty and nothing is flagged.
3. **Nothing is left out by mistake.** If **Left out because not yet reconciled** is more than 0, some eligible donations are still waiting in the reconciliation inbox. They join the claim once reconciled. Reconcile them in Scoutworks and run the check again.

## 5. Switch to your group

Change `api-demo.scoutworks.app` to `api.scoutworks.app`, set `TAX_YEAR`, and replace the sandbox key with your own. The key needs `gift-aid:read`. Add `gift-aid.people:read` for the donor columns: without it they are empty, but the totals still work.

> [!WARNING]
>
> With `gift-aid.people:read`, the **Claim lines** tab holds donors' names and home addresses. Share it only with the person checking the claim, and delete it once the claim is sent.

## If something goes wrong

* **`400 invalid_request`**: `TAX_YEAR` must look like `2025-26`.
* **The toast says there are too many donations for one claim**: the summary's `truncated` is true, because the year holds more than 5,000 donations of one kind. The figures are then too low. [Contact us](https://scoutworks.app/contact) before you claim.

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.