# Clicks

> Search with a lead, then send the person to the ICON link of the click result they choose.

A clicks campaign takes click results only. It searches like the affiliate API, and its results carry an ICON link instead of a submit: you send the person to the link of the result they choose, and ICON records the click for you.

## What you need

Everything comes from your login to ICON (**Campaigns**, then the campaign):

| What | Where |
| --- | --- |
| Your API keys | Created on your campaign's page. Each starts with `icak_` and is shown once. |
| The values that name your campaign | Listed on your campaign's page under "Send these on every record". |
| Your campaign's click offers | Listed on your campaign's page, with their offer ids. |
| Whether your campaign is in testing | Shown on your campaign's page. While it is, every lead you post is held as a test. |

## Clicks: send the person to the result's link

- 1. `POST /api/v1/engine/search` with the lead, `icon_campaign_id` and `icon_affiliate_id`, then `GET /api/v1/engine/results/{icon_lead_id}` until `processing_done` is `true`, waiting `poll_after_ms` (1000 ms) between polls.
- 2. A click result is not submitted: it carries an ICON link in `delivery.click_out_url`. Send the person to that link when they choose the result.
- Always use `delivery.click_out_url`, never `delivery.outbound_url`: only ICON's link records the click for you. The link names your search, so use it only for the person who searched.
- A click result without the link is not ready to be clicked: leave it out.
- To have your own IDs back on a click, send them with the search: your click ID as `tracking.aff_click_id` and up to five sub IDs as `tracking.sub1` to `tracking.sub5` (`aff_sub` to `aff_sub5` also work). ICON records them on every click from that search, for your postbacks.

## Example

Search (the lead, your campaign and affiliate ids):

```bash
curl -X POST 'https://iconroute.io/api/v1/engine/search' \
  -H "Authorization: Bearer $ICON_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "icon_campaign_id": "6f1c2d3e-4a5b-4c6d-8e9f-0a1b2c3d4e5f",
  "icon_affiliate_id": "3c9d8e7f-1a2b-4c3d-9e8f-7a6b5c4d3e2f",
  "lead": {
    "personal": {
      "first_name": "Ada",
      "last_name": "Lovelace",
      "email": "ada.lovelace@mail.test",
      "phone": "6025552368",
      "date_of_birth": "1990-04-07"
    },
    "address": {
      "address_line_1": "123 N Main St",
      "city": "Phoenix",
      "state": "AZ",
      "zip_code": "85004"
    },
    "education": {
      "education_level": "bachelors",
      "high_school_graduation_year": "2008",
      "start_timeline": "1_3_months",
      "learning_preference": "online"
    },
    "background": {
      "military_affiliation": "none",
      "us_citizen": "yes"
    }
  },
  "tracking": {
    "ip_address": "203.0.113.9",
    "subid": "pub-42",
    "subid2": "creative-7",
    "utm_source": "partner",
    "utm_medium": "email",
    "utm_campaign": "fall-enrollment"
  },
  "tcpa_consent": true,
  "trusted_form_cert_url": "https://cert.trustedform.com/0123456789abcdef0123456789abcdef01234567"
}'
```

Poll until `processing_done` is `true`:

```bash
curl -X GET 'https://iconroute.io/api/v1/engine/results/1e8d30bb-7c5f-41b9-8cf1-5e6b57abe999' \
  -H "Authorization: Bearer $ICON_API_KEY"
```

A click result, as it comes in `offers`:

```json
{
  "icon_result_id": "api-0b7e4a2c-981234",
  "campaign_id": "6f1c2d3e-4a5b-4c6d-8e9f-0a1b2c3d4e5f",
  "offer": {
    "id": "0b7e4a2c-9d8f-4e1a-b2c3-d4e5f6a7b8c9",
    "name": "Example University",
    "offer_type": "click_offer",
    "is_exclusive": false,
    "tcpa_text": null
  },
  "school": {
    "name": "Example University",
    "logo_url": "https://cdn.example.com/logo.png"
  },
  "programs": [],
  "form_fields": [],
  "delivery": {
    "click_out_url": "<the ICON link to send the person to>"
  },
  "expires_at": "2026-09-25T20:15:00Z"
}
```

Send the person to `delivery.click_out_url`. A Students campaign whose offers include click offers gets click results the same way, next to its lead results.

## Your API keys

- Every request to your campaign must carry one of its API keys, in a header: `Authorization: Bearer <key>` or `X-API-Key: <key>`. A request without a key is refused (HTTP 401 `AUTH_REQUIRED`), and so is a key ICON does not know or has revoked (HTTP 401 `AUTH_INVALID`). On a post, a key in the query string is refused as `partner_key_header_only` (HTTP 401: revoke it, it may be in someone's logs), and a key in the body is not read at all (HTTP 403 `FORBIDDEN`, `partner_key_required`).
- A post to another of your own campaigns with this key is refused (HTTP 403 `FORBIDDEN`, `campaign_not_allowed_for_key`), and so is a post to a campaign that is not yours (`campaign_outside_scope`). A search that names a campaign the key does not belong to is refused the same way (`campaign_not_allowed_for_key`).
- Create the key on your campaign's page in ICON. It starts with `icak_` and is shown once, when you create it: store it then. ICON keeps only a fingerprint of it, so ICON can't show it again, to you or to anyone.
- A key belongs to one campaign and one lane: web or call center. Every lead a key sends is a lead of its lane.
- Optional: when you create a key, list the IP addresses or ranges your servers send from (up to 20). A request from any other address is refused: a post with HTTP 403 `FORBIDDEN`, `ip_not_allowed_for_key`; a search, results poll or pre-check with HTTP 401 `AUTH_INVALID`. Leave the list empty to allow any address.
- A campaign can have up to 5 live keys per lane. To replace a key, create the new one, move your traffic to it, then revoke the old one: both work in between.
- A key ICON issued to you before you could create your own is refused (a post with HTTP 403 `FORBIDDEN`, `api_key_reissue_required`; a search, results poll or pre-check with HTTP 401 `AUTH_INVALID`): create a new key on your campaign's page and revoke the old one.

## Answers to a search

A search and a results poll answer your key like this ([Search](https://developers.iconroute.io/api/search/#errors) lists their other errors). A refused key carries no finer reason than `AUTH_INVALID`:

| code | HTTP | status | Send again? | When |
| --- | --- | --- | --- | --- |
| `AUTH_REQUIRED` | 401 | invalid | no | The request carried no API key. |
| `AUTH_INVALID` | 401 | invalid | no | The key is unknown or revoked, the request came from outside its IP allowlist, or it is an older key ICON issued to you (create a new one on your campaign's page). |
| `FORBIDDEN` | 403 | invalid | no | A search named a campaign this key does not belong to (search only). `reason: "campaign_not_allowed_for_key"`: Search with the key of the campaign you name. |
| `RATE_LIMITED` | 429 | failed | yes, later | The key is over its limit. Wait the seconds in the `Retry-After` header, then send it again. |
