Skip to content

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; 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

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

For other failures, follow Troubleshoot API requests. Keep the X-Request-ID response header, but do not keep the key or response data in logs.

Next steps

Remove the temporary environment variable when you finish:

bash
unset MOCHI_API_KEY