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

# Build a beneficiary picker

> Let a person find a charity or campaign by name, show each match, and read the one they chose

A picker is a search box that lists matches as the person types, and a way to look closer at one
of them. Both are public reads on `https://api.donate.gg/api/v2`. Call them from your server.

## Search as the person types

[`GET /v2/beneficiaries?term=`](https://docs.donate.gg/api-reference/beneficiaries/list) returns the charities and
campaigns that match, ranked together, best match first.

```bash theme={null}
curl "https://api.donate.gg/api/v2/beneficiaries?term=make-a-wish%20america&limit=5"
```

An example answer:

```json theme={null}
{
  "items": [
    {
      "type": "charity",
      "id": "9b4dae4e-d8c1-4322-a594-35a4858296b2",
      "available": true,
      "name": "Make-A-Wish America",
      "imageUrl": "https://docs.candid.org/edoc/11142134",
      "url": "https://www.donate.gg/charities/make-a-wish-america",
      "source": null,
      "eligible": true,
      "receiverCount": 1
    }
  ],
  "nextCursor": null
}
```

A campaign comes back in the same list, with the same fields:

```json theme={null}
{
  "type": "campaign",
  "id": "cmr2icrm701xu04jxvybvmgwn",
  "available": true,
  "name": "Kintara for St. Jude",
  "imageUrl": "https://donategg-user-assets-prod.s3.us-east-1.amazonaws.com/image/e6a658a4-ee8a-4428-960d-56e16bfe9c91/1874bf55-7026-40be-a1ff-5fbedb6a0fd1.png",
  "url": "https://www.donate.gg/campaigns/kintara-for-st-jude",
  "source": "donate",
  "eligible": true,
  "receiverCount": 1
}
```

| Parameter | Required | Values |
| - | - | - |
| `term` | Yes | 1 to 200 characters after trimming |
| `type` | No | `charity` or `campaign`. Omit for both |
| `source` | No | `donate` or `tiltify`: campaigns from this source only. Needs `type=campaign` |
| `limit` | No | 1 to 50. Default 25 |
| `cursor` | No | The previous page's `nextCursor` |

On a coin page, read `GET /v2/configs/{configId}/beneficiaries` for weighted campaign, charity and person profiles. Charity profiles include their website and socials. A campaign includes its supported beneficiaries with weights relative to each other. When a campaign completes it remains the named recipient, and existing coins continue paying it.

What to know before you design the picker:

* **The picker is empty until the person types.** `term` is required, so there is nothing to show
  before the first character. [Suggestions](#suggestions-before-the-person-types) says what you
  can show there if you want something.
* **Search returns only what can go into a new config.** A result is selectable when it appears,
  and returns `eligible: true`. Config creation checks eligibility again.
* Add up the selected results’ `receiverCount` values to check the five-recipient limit. A charity
  or Tiltify campaign counts once. A Donate campaign counts once per charity it pays.
* To load more matches, send `nextCursor` as the `cursor` query parameter with the same `term`,
  `type` and `source`. A null cursor means you have reached the last page.
* **Types share the limit.** Charities and campaigns are ranked together with no quota for
  either, so a common word can fill the list with one type. If your picker has tabs, send one
  request per tab with `type=charity` and `type=campaign`.
* **`source` filters campaigns.** `donate` is a campaign created on donate.gg and `tiltify` one
  imported from Tiltify. Sending `source` without `type=campaign` answers `400`.
* **An unknown parameter is refused.** A cache-busting parameter such as `?_=123` answers `400`.
* **Names can repeat.** Two charities or two campaigns can share a name.
  [Read the chosen one in full](#read-one-in-full) to tell them apart.

A refused request names the parameter in `issues`:

```bash theme={null}
curl "https://api.donate.gg/api/v2/beneficiaries?term=st%20jude&source=donate"
```

```json theme={null}
{
  "code": "VALIDATION_ERROR",
  "message": "The query is invalid.",
  "issues": [{ "path": "source", "code": "invalid", "message": "source requires type=campaign" }]
}
```

## Show a result

Every search result has the same fields, so one row component can show charities and campaigns.

| Field | Show it as |
| - | - |
| `imageUrl` | The logo. It can be `null`: show your own fallback, such as the first letter of the name |
| `name` | The name. It can be `null` on a recipient you resolve by id; a search result always has one |
| `type` | A badge: "Charity" for `charity`, "Campaign" for `campaign` |
| `url` | The recipient's page on donate.gg. Linking to it is welcome. `null` when it has none |
| `source` | Where a campaign came from. `null` for a charity |
| `available` | `true` on every search result |
| `id` | Not shown. Keep it with `type`: the two together are the recipient |

Keep `type` and `id` for the choice. The two together are the beneficiary you name in a config.

A charity has a page on donate.gg only once it has signed up there. One that has not is still a
result, with its own name and logo, and can be named in a config: only its `url` is `null`.

> [!NOTE]
>
> More kinds of recipient will be added, and research is the next one. A new kind shares the same
> display fields. When you meet a `type` you do not know, show the row from `name`, `imageUrl` and
> `url`, with a neutral badge, and do not open a details view for it.

### Keep within the rate limit

Each keystroke is a request. Wait until the person pauses typing (250 ms works well), drop the
answer to a request you no longer need, and send your API key from your server so searches count
against your organization's limit instead of the 20 a minute an IP address gets. See
[Rate limits](https://docs.donate.gg/api/rate-limits.md).

### Suggestions before the person types

Search needs a term. To fill the list before anyone types, show the charities and campaigns
that have raised the most: [`GET /v2/charities?sort=raised`](https://docs.donate.gg/api-reference/charities/list) and
[`GET /v2/campaigns?sort=raised`](https://docs.donate.gg/api-reference/campaigns/list). An item of either list starts
with the same seven fields as a search result.

### A directory of every charity

[`GET /v2/charities`](https://docs.donate.gg/api-reference/charities/list) pages through every charity listed on
Donate, each in full with its totals. It is for a browse page, where the search above is for a
box someone types in.

```bash theme={null}
curl "https://api.donate.gg/api/v2/charities?sort=raised&limit=25"
```

| Parameter | Values |
| - | - |
| `term` | Keeps only the charities that match this text |
| `sort` | `name` (A to Z), `newest`, `raised` (by `stats.totalUsdE6`), `recent` (by `stats.lastDonationAt`), or `relevance` with `term` |
| `limit` | 1 to 100. Default 25 |
| `cursor` | The `nextCursor` of the previous page, with the same `term` and `sort` |

Without `sort` the order is `name`, or `relevance` when you send `term`. Each item is the same
object as [`GET /v2/charities/{charityId}`](https://docs.donate.gg/api-reference/charities/get) returns. A charity
that is hidden, disabled or has opted out is never in the list.

## Read one in full

A search result is a summary. To show more before the person confirms, read the one they chose by
its `type`.

> [tab] type: charity
>
> ```bash theme={null}
> curl "https://api.donate.gg/api/v2/charities/9b4dae4e-d8c1-4322-a594-35a4858296b2"
> ```
>
> [`GET /v2/charities/{charityId}`](https://docs.donate.gg/api-reference/charities/get) starts with the same seven
> fields and adds the mission (`description`), `websiteUrl`, `registrationNumber` with its
> `country`, `location`, `socials`, and `stats`, which is everything the charity has received
> through Donate. The city and the registration number are what tell two charities with the same
> name apart.

> [tab] type: campaign
>
> ```bash theme={null}
> curl "https://api.donate.gg/api/v2/campaigns/cmr2icrm701xu04jxvybvmgwn"
> ```
>
> [`GET /v2/campaigns/{campaignId}`](https://docs.donate.gg/api-reference/campaigns/get) starts with the same seven
> fields and adds the story (`description`), `media`, `goalUsdE6`, `status`, `categoryId`,
> `sourceUrl`, and `stats`, which is what the campaign has raised through Donate.

Both have `eligible`. It is `true` when the recipient can be named in a new config. A completed
campaign stays readable with `eligible: false`. Eligibility is checked again when you create the
config, so treat it as a hint for your interface, not a guarantee.

[Show what a coin donates to](https://docs.donate.gg/guides/coin-page.md#3-the-details-view) has both responses in full and
the field to use for each part of a details view.

## When the charity is not listed

If the person cannot find a charity, it may not be on Donate yet. You can look it up in an
official register and ask for it to be added. See [Request a charity](https://docs.donate.gg/guides/request-a-charity.md).

## Next

With a `type` and an `id` for each choice, create the config:
[`POST /v2/configs`](https://docs.donate.gg/api-reference/configs/create). The [coin guide](https://docs.donate.gg/guides/coin-launchpad.md) and
the [donate button guide](https://docs.donate.gg/guides/donate-button.md) show where it goes from there.

## Runnable sequence

```bash theme={null}
# Both types, ranked together
curl "https://api.donate.gg/api/v2/beneficiaries?term=make-a-wish%20america&limit=5"

# One request per tab
curl "https://api.donate.gg/api/v2/beneficiaries?term=st%20jude&type=charity&limit=10"
curl "https://api.donate.gg/api/v2/beneficiaries?term=st%20jude&type=campaign&limit=10"

# Campaigns created on donate.gg only
curl "https://api.donate.gg/api/v2/beneficiaries?term=st%20jude&type=campaign&source=donate"

# source without type=campaign is refused
curl "https://api.donate.gg/api/v2/beneficiaries?term=st%20jude&source=donate"

# The directory of every charity, most raised first
curl "https://api.donate.gg/api/v2/charities?sort=raised&limit=25"

# Read the chosen one in full
curl "https://api.donate.gg/api/v2/charities/9b4dae4e-d8c1-4322-a594-35a4858296b2"
curl "https://api.donate.gg/api/v2/campaigns/cmr2icrm701xu04jxvybvmgwn"
```


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