# Make your first API request

In this guide, you will ask Mochi for up to ten leads. This is a **read-only** request: it cannot add, change, or
delete data.

## What you need

You need three things:

1. An **API key** for your organization. This is a controlled pilot, so Settings → Developers appears only after
   Mochi manually approves your exact organization. If it is available, follow
   [Create and manage an API key](https://themochi.app/docs/api/start-here/manage-api-keys); otherwise contact Mochi instead of trying a direct URL.
2. The `leads:read` **scope**. A scope is a permission. This one allows the key to read leads.
3. A terminal on a trusted computer or server. Do not run this example in browser JavaScript, where visitors could
   see the key.

Mochi shows a new key only once. Save it in a server-side secret manager. Do not paste a real key into source code,
documentation, screenshots, prompts, or support messages.

## Step 1: set the key for this terminal

Run the first command, paste the key when the cursor waits, and press Enter. The terminal does not display the key,
and the key does not become part of the command in your shell history. The second command makes it available to
cURL:

```bash
read -s MOCHI_API_KEY
export MOCHI_API_KEY
```

## Step 2: request up to ten leads

```bash
curl --fail --silent --show-error \
  --request GET \
  --url "https://api.themochi.app/v1/leads/?page_size=10" \
  --header "Authorization: Bearer ${MOCHI_API_KEY}" \
  --header "Accept: application/json"
```

## Step 3: confirm success

A successful response has this shape:

```json
{
  "data": [],
  "next_cursor": null
}
```

`data` is the list of leads. It may be empty when the organization has no leads. `next_cursor` tells you whether
another page exists. You do not need it for this first request.

Your first request succeeded if cURL exits without an error and the response contains both fields. The request can
return only leads from the organization linked to the key.

## If the first request fails

| Result | What to do |
| --- | --- |
| `401` | The key is missing, invalid, expired, or revoked. Check that the environment variable is set without printing its value. |
| `403` | The key does not have `leads:read`. Ask for that permission instead of a broader key. |
| `404` | Check the base URL and path. The endpoint may not be enabled for your organization. |
| `429` | Wait for the number of seconds in the `Retry-After` response header, then try again. |

For other failures, follow [Troubleshoot API requests](https://themochi.app/docs/api/troubleshooting-and-safety/diagnose-api-failures). Keep the `X-Request-ID` response
header, but do not keep the key or response data in logs.

## Next steps

- Use the same request in [cURL, Python, Node.js/TypeScript, or PHP](https://themochi.app/docs/api/start-here/code-examples).
- Learn how to [load every page](https://themochi.app/docs/api/troubleshooting-and-safety/pagination).
- [Choose how to authenticate](https://themochi.app/docs/api/start-here/authentication) for a scheduled job, browser app, or AI tool.
- [Create and manage an API key](https://themochi.app/docs/api/start-here/manage-api-keys) if Mochi has approved your organization for the controlled pilot.
- Follow [Test your integration safely](https://themochi.app/docs/api/troubleshooting-and-safety/testing-guide) before requesting write permissions.

Remove the temporary environment variable when you finish:

```bash
unset MOCHI_API_KEY
```
