# Host & Post

> Post a full lead to one offer of your campaign, with its offer id and the fields that offer requires, and read the answer in the same call.

A Host & Post campaign posts each lead straight to one of its offers: `POST /api/v1/engine/leads` with the whole lead, your campaign and affiliate ids and the offer's `icon_offer_id`. No search: ICON checks the lead and answers in the same call.

## 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". |
| Each offer's id and required fields | Listed on your campaign's page, one block per offer: its `icon_offer_id`, the fields it requires and, per media, what it adds. |
| Whether your campaign is in testing | Shown on your campaign's page. While it is, every lead you post is held as a test. |

## Host & Post: post a full lead to one offer

- `POST /api/v1/engine/leads` with the whole lead, `icon_campaign_id`, `icon_affiliate_id` and the `icon_offer_id` of the offer you post it to. One request per lead and offer: to post the same lead to two offers, send it twice, once with each offer id.
- Send the fields that offer requires (each offer's are listed on your campaign's page) and the person's own IP address as `tracking.ip_address`, never your server's.
- Show the offer's consent statement before you post, and send the person's decision as `tcpa_consent` with the label of the button they pressed as `consent_button_label`.
- ICON answers in the same call with the outcome: `ACCEPTED`, or why it was not. Keep the answer's `icon_lead_id` with your lead to ask your account manager about it. Once a lead was submitted, a post that would change it is refused (HTTP 403 `FORBIDDEN`): to correct a lead, ask your account manager.
- A post that names your campaign but no offer is only stored (`SAVED`): nothing is sent. Name the offer.
- An offer whose school ICON calls through its own API is not posted to directly: it is reached through a search instead.

## Your first post

Post a test lead. Send `icon_is_test_lead: true` on a search or a post: the lead runs every check and is held in ICON before any school or provider hears of it (no post, no ping, no click-out redirect). It is not counted against caps and not paid. Every answer is exactly the live one, with `"testing": true` added; an accepted post shows the payout it would earn. While your campaign is in testing you need no flag: every lead is held the same way.

```bash
export ICON_API_KEY='<your API key>'
```

```bash
curl -X POST 'https://iconroute.io/api/v1/engine/leads' \
  -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",
  "icon_offer_id": "0b7e4a2c-9d8f-4e1a-b2c3-d4e5f6a7b8c9",
  "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"
  },
  "program_id": "4411",
  "tcpa_consent": true,
  "trusted_form_cert_url": "https://cert.trustedform.com/0123456789abcdef0123456789abcdef01234567",
  "icon_is_test_lead": true
}'
```

The answer has `code: "TEST_LEAD_HELD"` and `status: "held"`. Take the ids above from your campaign's page. Without the test flag the answer is `ACCEPTED` or the reason it was not; see [Submit a lead](https://developers.iconroute.io/api/leads/#response).

## 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.

## Call-center leads

- Send call-center leads with your call-center key: the key's lane makes the lead a call-center lead. Send the fields each offer requires for call-center leads (listed on your campaign's page).
- Every call-center lead a school accepts owes ICON its call recording. The recording does not hold up the lead: it is due after the sale, normally within a few hours and at the latest by the end of that day. Your account manager tells you how to send recordings.

## Web and call-center leads on one campaign

- This campaign takes web and call-center leads. Create one key per lane: a web key and a call-center key.
- Each lead's media is the lane of the key that sent it: send web leads with the web key and call-center leads with the call-center key. A request never says its media itself.
- ICON never guesses a lead's media: a request to this campaign without a key is refused (HTTP 401 `AUTH_REQUIRED`), and one whose key has no lane is refused (HTTP 403 `FORBIDDEN`, `blended_campaign_lane_key_required`).

## Answers

Every answer carries `status`, `reason`, `code` and `retryable`. Branch on `code`, not the HTTP status: a decision about a lead usually comes with HTTP 200. These are the answers you are most likely to meet; [Standard responses](https://developers.iconroute.io/responses/) lists every code.

| code | HTTP | status | Send again? | When |
| --- | --- | --- | --- | --- |
| `ACCEPTED` | 200 | accepted | no | The lead was accepted. |
| `SAVED` | 200 | saved | no | The post named your campaign but no offer (or no result), so the lead was only stored: nothing was sent. Post it again with the offer id, or submit a result. |
| `PENDING` | 200, 202 | pending | no | The school has not decided yet. Do not send it again. |
| `AUTH_REQUIRED` | 401 | invalid | no | The post carried no API key. `reason: "missing_api_key"`: No key was sent. |
| `AUTH_INVALID` | 401 | invalid | no | ICON does not know the key, or it was revoked, or it was sent in the query string. `reason: "invalid_api_key"`: An unknown or revoked key. `reason: "partner_key_header_only"`: The key was in the query string. Send it in a header, and revoke it: it may be in someone's logs. |
| `FORBIDDEN` | 403 | invalid | no | The key may not make this post. `reason: "partner_key_required"`: Your campaign takes posts only with one of its own keys, in a header (a key in the body is not read). `reason: "campaign_not_allowed_for_key"`: The key belongs to another of your campaigns. A key works for its own campaign only. `reason: "campaign_outside_scope"`: The post named a campaign that is not yours. `reason: "ip_not_allowed_for_key"`: The post came from an address outside the key's IP allowlist. `reason: "api_key_reissue_required"`: An older key ICON issued to you: create a new key on your campaign's page and revoke this one. `reason: "blended_campaign_lane_key_required"`: Your campaign takes web and call-center leads: send each with a key of its lane. `error: "result_campaign_mismatch"`: A result submit named a campaign the result does not belong to. Name the result's campaign, or none. `error: "lead_already_submitted"`: The post would change a lead that was already submitted. Nothing was saved or sent; corrections are made in ICON. |
| `NOT_FOUND` | 404 | invalid | no | The result you submitted is not one of yours. Submit a result of your own search. `error: "search_result_not_found"`: No search result with that id belongs to your key. |
| `OFFER_UNAVAILABLE` | 200, 410 | rejected | no | The offer, or your campaign, is paused or not live, or the result expired. Leads sent now are not accepted. |
| `REQUIRED_FIELD_MISSING` | 200, 400 | invalid | no | A required field is missing; `field` names it. |
| `INVALID_FIELD` | 200, 400 | invalid | no | A field has a value ICON does not accept; `field` names it. |
| `CONSENT_REQUIRED` | 200 | invalid | no | The lead does not carry the consent the offer requires. |
| `JORNAYA_MISSING` | 200 | invalid | no | The offer requires a Jornaya LeadiD and the lead has no valid one. |
| `TRUSTEDFORM_MISSING` | 200 | invalid | no | The offer requires a TrustedForm certificate and the lead has no valid one. |
| `NOT_ELIGIBLE` | 200 | rejected | no | The lead is outside what the offer takes, for example its programs, area or hours. A clicks campaign takes click results only: a lead posted to it is answered `NOT_ELIGIBLE`. |
| `CAP_REACHED` | 200 | rejected | no | The offer or your campaign has taken all the leads it can for now. |
| `DUPLICATE` | 200, 409 | rejected | no | ICON or the school already has this person for the offer. Not paid. |
| `BUYER_REJECTED` | 200 | rejected | no | The lead passed ICON's checks and the school refused it. |
| `RATE_LIMITED` | 429 | failed | yes, later | The key is over its limit. Wait the seconds in the `Retry-After` header, then send it again. |
| `UNAVAILABLE` | 200, 503 | failed | yes, later | ICON could not complete the checks; nothing was delivered. Send it again later. `reason: "api_key_lane_unverifiable"`: ICON could not read your key just now (HTTP 503). Send it again. |
| `INTERNAL_ERROR` | 500 | failed | no | Something failed on ICON's side. Do not resend it as is; tell your account manager the time and the answer's `request_id`. |

## Next

- Ask whether ICON would call a lead a duplicate before you post it: [Duplicate pre-check](https://developers.iconroute.io/api/dupe-check/), when your campaign's page lists it.
- Show the offer's consent statement and send the decision: [Consent and TCPA](https://developers.iconroute.io/consent/).
- Every field's format: [Field dictionary](https://developers.iconroute.io/fields/).
