> For the complete documentation index, see [llms.txt](https://docs.humblytics.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.humblytics.com/agent-onboarding-api.md).

# Agent Onboarding API

The Agent Onboarding API lets AI agents sign up users, handle plan selection and payment, and receive an API token — all without the user opening a dashboard. This is designed for Claude Code, Cursor, and any agent that wants to onboard users programmatically.

> **Base URL**: `https://app.humblytics.com`

***

## Overview

Use [Activate with an email](#recommended-activate-with-an-email) below. The older flow that follows (`agent-initiate`) still works.

The older signup flow has two parts:

1. **The agent** calls `/api/v1/auth/agent-initiate` to create a session and get a unique verification URL.
2. **The user** opens that URL in their browser to verify identity and complete payment.
3. **The agent** polls until the session is complete, then receives an `authToken` for all subsequent API calls.

***

## Recommended · Activate with an email

The default way for an agent with no Humblytics credentials to get a key. The agent sends the person's email and site plus a short proof of work. Humblytics emails the person one **Activate** button. That click creates the account (Free start: 5,000 data points, 1 site, no card) or uses the existing one (without signing the browser in), adds the site, attaches a homepage audit if one was sent, and releases an account API key to the agent's poll. There is no sign-in page and no email code.

### 1 · Get a challenge

`GET /api/v1/agent/activate/challenge`

| Query parameter | Required | Description                                     |
| --------------- | -------- | ----------------------------------------------- |
| `email`         | Yes      | The person's email                              |
| `url`           | Yes      | Their site, as a domain (`mysite.com`) or a URL |

```bash
curl "https://app.humblytics.com/api/v1/agent/activate/challenge?email=jane@example.com&url=mysite.com"
```

```json
{
  "nonce": "3f9c1e0a7b2d4c6e8f1a2b3c4d5e6f70",
  "timestamp": 1794950000000,
  "difficulty": 18,
  "signature": "9a1f…"
}
```

The challenge is bound to that email and site and is valid for 10 minutes. `400 invalid_email` or `400 invalid_url` when a parameter is unusable.

### 2 · Solve the proof of work

Find a whole number `counter` (0, 1, 2, …) where SHA-256 of the text `<nonce>|<counter>` starts with `difficulty` zero bits. It takes a few seconds.

```javascript
const crypto = require("crypto");
const solve = (nonce, difficulty) => {
  for (let counter = 0; ; counter++) {
    const hash = crypto.createHash("sha256").update(`${nonce}|${counter}`).digest();
    let bits = 0;
    for (const byte of hash) {
      if (byte === 0) { bits += 8; continue; }
      bits += Math.clz32(byte) - 24;
      break;
    }
    if (bits >= difficulty) return counter;
  }
};
```

### 3 · Send the activation request

`POST /api/v1/agent/activate`

| Field                             | Required | Description                                                                                               |
| --------------------------------- | -------- | --------------------------------------------------------------------------------------------------------- |
| `email`, `url`                    | Yes      | The same values the challenge was made for                                                                |
| `nonce`, `timestamp`, `signature` | Yes      | From the challenge, unchanged                                                                             |
| `counter`                         | Yes      | The solved counter (number or decimal string)                                                             |
| `agent_name`                      | No       | Your name as the person should see it, e.g. `Claude Code`                                                 |
| `name`                            | No       | The person's name, used for a new account                                                                 |
| `audit_token`                     | No       | An `hbt_` token from the Humblytics homepage audit; the audit and its drafted tests are saved to the site |

```bash
curl -X POST https://app.humblytics.com/api/v1/agent/activate \
  -H "Content-Type: application/json" \
  -d '{"email":"jane@example.com","url":"mysite.com","agent_name":"Claude Code","nonce":"3f9c…","timestamp":1794950000000,"signature":"9a1f…","counter":181234}'
```

```json
{
  "status": "ok",
  "poll_token": "hbp_…",
  "poll_url": "https://app.humblytics.com/api/v1/agent/activate/poll/hbp_…",
  "expires_at": "2026-11-18T21:00:00.000Z"
}
```

Every valid proof gets this same answer, whether the email is new, already has an account, or has hit its daily limit, so the response never reveals who has an account. Only a wrong, expired or reused proof answers `400 INVALID_PROOF_OF_WORK`: get a new challenge and solve it again.

### 4 · The person clicks Activate

Tell the person to check their inbox for the email from Humblytics and click **Activate**. Opening the link shows a confirm page; only the button activates, so email link scanners can't use it up. The link lasts 24 hours.

### 5 · Poll for the key

`GET <poll_url>` every 3 to 5 seconds.

```bash
curl https://app.humblytics.com/api/v1/agent/activate/poll/hbp_…
```

```json
{ "status": "pending" }
```

```json
{
  "status": "approved",
  "apiKey": "hmbl_…",
  "email": "jane@example.com",
  "propertyId": "c12c…",
  "site": "mysite.com"
}
```

`apiKey` is returned once, on the first `approved` answer; later polls answer `approved` without it. `propertyId` is `null` (with `siteLimitReached: true`) when the account already has its 1 Free start site. `expired` means the link timed out or a newer request for the same email and site replaced it.

**Notes**

* The key is an account-level key with the same permissions as other agent keys. Launching a split test still needs the person's approval.
* Use the key with the MCP server `https://mcp.humblytics.com/v1` (`Authorization: Bearer <apiKey>`), then follow [agent.md](https://app.humblytics.com/agent.md) from Step 2.
* Limits: one live link per email and site (a new request replaces the old link), and daily caps per email and per IP. Nothing is created and no tracking runs until the click.
* The endpoint is also listed as `agent_activation_endpoint` in `https://app.humblytics.com/.well-known/oauth-authorization-server`.

***

## Step 1 · Initiate Signup

Create a signup session for a new user.

**Request**

```bash
curl -X POST https://app.humblytics.com/api/v1/auth/agent-initiate \
  -H "Content-Type: application/json" \
  -d '{ "email": "user@example.com", "name": "Jane Smith" }'
```

**Parameters**

| Name    | Type   | Required | Description          |
| ------- | ------ | -------- | -------------------- |
| `email` | string | Yes      | User's email address |
| `name`  | string | Yes      | User's full name     |

**Response (201)**

```json
{
  "token": "<session-token>",
  "verifyUrl": "https://app.humblytics.com/agent-verify?token=<session-token>",
  "expiresAt": 1234567890000
}
```

**Error Responses**

| Status | Body                           | Meaning                      |
| ------ | ------------------------------ | ---------------------------- |
| 409    | `{ "error": "user_exists" }`   | Email already has an account |
| 400    | `{ "error": "invalid_email" }` | Email format is invalid      |

{% hint style="info" %}
The session expires in **10 minutes** if the user doesn't open the verification link.
{% endhint %}

***

## Step 2 · User Verification

Tell the user to open the verification URL in their browser. The page will:

1. Silently verify the user is human
2. Create their Humblytics account and set a browser session
3. Ask them to choose **Business Monthly ($79/mo)** or **Business Annual ($65/mo, save $168/yr)**
4. Redirect to Stripe to complete payment
5. Show a confirmation page

{% hint style="warning" %}
The agent should present the URL clearly and wait for the user to complete the browser flow before proceeding.
{% endhint %}

***

## Step 3 · Poll for Completion

Poll every 3–5 seconds until `status` is `"complete"` or the session expires.

**Request**

```bash
curl https://app.humblytics.com/api/v1/auth/agent-signup-status?token=<session-token>
```

**While waiting**

```json
{ "status": "pending" }
```

**When complete**

```json
{
  "status": "complete",
  "authToken": "<jwt>"
}
```

**Error Responses**

| Status | Meaning                                      |
| ------ | -------------------------------------------- |
| 404    | Token not found                              |
| 410    | Session expired — ask the user to start over |

{% hint style="warning" %}
The `authToken` is delivered **once** — the session is deleted after this response. Store the token immediately.
{% endhint %}

***

## Step 4 · Use the Token

All subsequent API calls use the token as a Bearer header:

```http
Authorization: Bearer <authToken>
```

This token works with all Humblytics API endpoints including the [External Analytics API](https://docs.humblytics.com/external-analytics-api.md) and [Split Testing API](https://docs.humblytics.com/split-testing-api.md).

***

## Step 5 · Add a Website

With the token, the agent can immediately add a website to the account.

**Request**

```bash
curl -X POST https://app.humblytics.com/api/v1/add-custom-site \
  -H "Authorization: Bearer <authToken>" \
  -H "Content-Type: application/json" \
  -d '{ "domain": "example.com", "name": "My Site" }'
```

**Response**

```json
{
  "propertyId": "<property-id>",
  "scriptId": "<script-id>"
}
```

Install the tracking script on the user's site:

```html
<script async src="https://app.humblytics.com/hmbl.min.js?id=<script-id>"></script>
```

***

## Step 6 · Stripe Payment Links (Fallback)

If the user skipped payment during signup, send them directly to Stripe:

| Plan    | URL                                                                      |
| ------- | ------------------------------------------------------------------------ |
| Monthly | `https://buy.stripe.com/6oU9AS4TVdaQafZ9tS2Nq0k?prefilled_email=<email>` |
| Annual  | `https://buy.stripe.com/8x2cN40DF4EkafZ49y2Nq0j?prefilled_email=<email>` |

***

## Quick Reference

| Step                    | Method | Endpoint                                         |
| ----------------------- | ------ | ------------------------------------------------ |
| Activation challenge    | GET    | `/api/v1/agent/activate/challenge?email=&url=`   |
| Activate with an email  | POST   | `/api/v1/agent/activate`                         |
| Poll for the key        | GET    | `/api/v1/agent/activate/poll/<poll_token>`       |
| Initiate signup (older) | POST   | `/api/v1/auth/agent-initiate`                    |
| Poll for completion     | GET    | `/api/v1/auth/agent-signup-status?token=<token>` |
| Add a website           | POST   | `/api/v1/add-custom-site`                        |
| List websites           | GET    | `/api/v1/property/all`                           |
| Billing status          | GET    | `/api/v1/billing/status`                         |

***

## Agent Spec File

The full onboarding spec is available as a standalone markdown file that agents can load as context:

[**https://app.humblytics.com/agent.md**](https://app.humblytics.com/agent.md)

You can also open it directly in your editor:

* **Cursor**: [Add to Cursor](cursor://anysphere.cursor-deeplink/prompt?text=Fetch%20the%20Humblytics%20agent%20API%20spec%20from%20https%3A%2F%2Fapp.humblytics.com%2Fagent.md%20and%20save%20it%20as%20a%20cursor%20rule%20in%20.cursor%2Frules%2Fhumblytics.mdc) — opens Cursor and creates a rule from the spec
* **Claude Code**: Run `curl -o HUMBLYTICS.md https://app.humblytics.com/agent.md` then include in your CLAUDE.md

Add it to your `CLAUDE.md`, `.cursorrules`, or system prompt and your agent will know how to onboard users automatically.

***

## Related

* [API Access & Agent Setup](https://docs.humblytics.com/api-access-and-agents.md) — guided activation flow for API keys and marketing skills in the dashboard
* [External Analytics API](https://docs.humblytics.com/external-analytics-api.md) — Query traffic, pages, clicks, forms, and funnels
* [Split Testing API](https://docs.humblytics.com/split-testing-api.md) — Create and manage A/B tests programmatically
