> For the complete documentation index, see [llms.txt](https://help.theaffiliateplatform.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.theaffiliateplatform.com/apis-and-configurations/deals-management-api.md). Agents can also search and read this documentation through its [MCP server](https://help.theaffiliateplatform.com/~gitbook/mcp).

# Deals management API

{% hint style="info" %}
This document describes how to manage deals for affiliates via API.
{% endhint %}

{% hint style="danger" %}
The default API URL is **<https://boapi.smartico.ai/>** but depending on your setup it could be different. Check for the exact URL in the '***Settings***' section.
{% endhint %}

All calls on this page use the **operator API key**. Send it in the `authorization` header. To get the key, see [API Keys and URL](https://help.theaffiliateplatform.com/apis-and-configurations/api-keys-and-url.md).

## Creating new deals for affiliates

Use the HTTP POST method to create a deal for an affiliate (`affiliate_id`).

Example of the call:

```bash
curl --location 'https://boapi.smartico.ai/api/af2_deals_op' \
--header 'authorization: your-api-key' \
--header 'Content-Type: application/json' \
--data '{
     "affiliate_id": 64257,
     "deal_type_id": 6,
     "deal_group_name": "CPA + REV & FTD Qualifier",
     "cpa_amount": 10,
     "qua_cpa_ftd": 30,
     "rev_share_percentage": 25
}'
```

The platform supports the following deal types (`deal_type_id`):

```typescript

export enum AffDealType {
    // Pure deals
    CPL = 1,
    CPA = 2,
    RevShare_NetPL = 4,
    RevShare_NetDeposit = 8,

    // Hybrid deals
    CPL_CPA = 3,
    CPL_RevShare_NetPL = 5,
    CPA_RevShare_NetPL = 6,
    CPL_RevShare_NetDeposit = 9,
    CPA_RevShare_NetDeposit = 10,

    // No commission
    None = 16,
}
```

The deal type is a bit mask: 1 = CPL, 2 = CPA, 4 = Rev Share on Net P\&L, 8 = Rev Share on Net Deposit. A hybrid deal is the sum of its parts, for example 6 = CPA (2) + Rev Share on Net P\&L (4). Use only the values listed above.

Supported fields in POST body:

```typescript

{
    "affiliate_id": 64257,      // required, one of your affiliates
    "deal_type_id": 2,          // required, one of the deal types
    "deal_group_name": "Some name of the deal", // required, must be unique among the deals of this affiliate

    // parameters specific for CPA deal
    "cpa_amount": 10.5,         // required, CPA amount that will be paid for affiliate
    "qua_cpa_net_deposit": 10,  // optional, NetDeposit qualifier amount
    "qua_cpa_deposit": 20,      // optional, Deposit qualifier amount
    "qua_cpa_ftd": 10,          // optional, FTD qualifier amount
    "qua_cpa_volume": 100,      // optional, Volume (wagering) qualifier amount
    "qua_cpa_activity_count": 5, // optional, activities (bets) count qualifier amount

    // parameters specific for CPL deal
    "cpl_amount": 10.5,         // required, CPL amount that will be paid for affiliate
    "qua_cpl_volume": 100,      // optional, Volume (wagering) qualifier amount

    // parameters specific for RevShare deals (both P&L and NetDeposit based)
    "rev_share_percentage": 25, // required, % of rev share
    "qua_rev_on_cpa_option": 0, // optional, CPA + RevShare deals, "Qualify Rev Share on CPA": 0 - No, 1 - Based on Net Deposit, 2 - Based on Net PnL, 3 - Based on Revshare
    "deduct_chargeback": true,  // optional, RevShare on Net Deposit, deduct chargebacks (default true)
    "deduct_bonus": false,      // optional, RevShare on Net Deposit, deduct bonuses (default false)

    // parameters for setting the deal criteria
    // a criterion that is not passed is 'Any'
    "match_brand_ids": [123],         // optional, brand IDs
    "match_countries": ["CA", "US_CA"], // optional, country codes; US states as "US_" + state code
    "match_campaign_ids": [55],       // optional, campaign IDs of this affiliate
    "match_source_ids": ["facebook"], // optional, source IDs
    "match_date_from": "2027-06-01",  // optional, first day of the deal, cannot be in the past
    "match_date_till": "2027-06-30"   // optional, last day of the deal, cannot be before match_date_from
}
```

The required amounts follow the deal type:

* `cpa_amount` for every type with CPA (2, 3, 6, 10);
* `cpl_amount` for every type with CPL (1, 3, 5, 9);
* `rev_share_percentage` for every type with Rev Share (4, 5, 6, 8, 9, 10).

For hybrid deals, you can use a combination of parameters. For example, for CPA + RevShare\_NetPL deal, the required fields will be cpa\_amount and rev\_share\_percentage.

To add tiers, send the tier fields with the deal. Tiers are explained in [Managing Deals](https://help.theaffiliateplatform.com/affiliate-platform/managing-deals.md).

```typescript
{
    // CPA tiers, up to 5: tier start (cpa_tier_step_N) and CPA amount of the tier (cpa_tier_amount_N)
    "cpa_tiers_enabled": true,
    "cpa_tier_step_1": 0,
    "cpa_tier_amount_1": 50,
    "cpa_tier_step_2": 200,
    "cpa_tier_amount_2": 60,

    // RevShare tiers, up to 8: tier start (rev_tier_amount_N) and rev share % of the tier (rev_tier_percentage_N)
    // 0 - No, 1 - Reached amount (Net P&L), 2 - Reached FTDs, 3 - FTDs + Recalculation
    "rev_share_tiers_enabled": 2,
    "rev_tier_amount_1": 0,
    "rev_tier_percentage_1": 25,
    "rev_tier_amount_2": 10,
    "rev_tier_percentage_2": 30
}
```

If the affiliate has no default (home) deal yet, the new deal becomes the default deal. The response is the new deal as one object, with the fields shown in [Getting a list of deals for the affiliate](#getting-a-list-of-deals-for-the-affiliate). Keep its `deal_original_id`: other calls use it.

If the call fails, the API answers with HTTP status 500 and a `message`, for example:

```json
{ "message": "CPA amount (cpa_amount) is required for CPA based deals" }
```

**Example** of the call that creates a CPA + RevShare\_NetPL deal with

* CPA amount of: 10
* Rev share percentage: 25
* CPA FTD Qualifier: 30

```bash
curl --location 'https://boapi.smartico.ai/api/af2_deals_op' \
--header 'authorization: your-api-key' \
--header 'Content-Type: application/json' \
--data '{
    "affiliate_id": 64257,
    "deal_type_id": 6,
    "deal_group_name": "CPA + REV & FTD Qualifier",
    "cpa_amount": 10,    
    "qua_cpa_ftd": 30, 
    "rev_share_percentage": 25
}'
```

Such a deal will correspond to the following configurations made from the TAP backoffice:

<figure><img src="https://2789002490-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkbip9hFgRFwIv4mXJPnz%2Fuploads%2Fgi6FSBRObhyZTxt0QEcj%2Fimage.png?alt=media&amp;token=d42b1e1d-ea92-4789-acc3-5b0021f4292e" alt=""><figcaption><p>Deal builder (Affiliate account, Deals) with configurations matching the Example call</p></figcaption></figure>

### Creating a sub-deal

To create a sub-deal, add `deal_parent_original_id` with the `deal_original_id` of the parent deal. A sub-deal does not need `deal_group_name`. Its criteria must stay inside the criteria of the parent deal. If they do not, the API answers, for example: "Deal definition is not valid. You can use only Brands that are defined in the parent deal".

```bash
curl --location 'https://boapi.smartico.ai/api/af2_deals_op' \
--header 'authorization: your-api-key' \
--header 'Content-Type: application/json' \
--data '{
    "affiliate_id": 64257,
    "deal_parent_original_id": 39752,
    "deal_type_id": 6,
    "cpa_amount": 20,
    "rev_share_percentage": 30,
    "match_countries": ["CA"]
}'
```

## Updating a deal

Use the HTTP PUT method with the `deal_id` of the current version. Send the **whole deal**: take it from [Getting a list of deals for the affiliate](#getting-a-list-of-deals-for-the-affiliate), change what you need and send it back. A field you leave out is not kept, so a call without the tier fields removes the tiers.

```bash
curl --location --request PUT 'https://boapi.smartico.ai/api/af2_deals_op/93195' \
--header 'authorization: your-api-key' \
--header 'Content-Type: application/json' \
--data '{
    ...the deal as returned by GET...,
    "deal_group_name": "Default deal v2",
    "cpa_tiers_enabled": true,
    "cpa_tier_step_1": 0,
    "cpa_tier_amount_1": 50,
    "cpa_tier_step_2": 200,
    "cpa_tier_amount_2": 60
}'
```

* When the commission, qualifiers, criteria or tiers change, TAP closes the current version at the end of the day and creates a new one from the next day. The new version has a new `deal_id`; `deal_original_id` stays the same.
* A main deal needs a new `deal_group_name` for such a change. A sub-deal does not.
* Changes of other fields (for example the dates) update the current version.

### Tier fields

* A tier is saved only when both of its values are sent: `cpa_tier_step_N` and `cpa_tier_amount_N`, or `rev_tier_amount_N` and `rev_tier_percentage_N`.
* Up to 5 CPA tiers and 8 Rev Share tiers; fields beyond that are ignored.
* CPA tiers apply to the deal types with CPA (2, 3, 6, 10), Rev Share tiers to the types with Rev Share (4, 5, 6, 8, 9, 10); a hybrid deal can have both.
* To remove the tiers, send `cpa_tiers_enabled: false` or `rev_share_tiers_enabled: 0` without the tier fields.
* There are no limits on tier steps, amounts or percentages.

## Set default deal for affiliate

You can use the HTTP POST method to set a default deal for the affiliate. In the TAP back office, the default deal is the **Home deal** (button **Make home deal**). Pass the `deal_original_id` of the deal.

Example of the call:

```bash
curl --location 'https://boapi.smartico.ai/api/private-api?method=af2_MakeDealDefault' \
--header 'authorization: your-api-key' \
--header 'Content-Type: application/json' \
--data '{
    "method": "af2_MakeDealDefault",
    "params": {
        "deal_original_id": 39752, 
        "affiliate_id": "64257"
           }
        }'
```

\
Example of the response:

```bash
 { "errCode":0, "message":"Deal group 39752 is set to be default" }
```

{% hint style="warning" %}
Check the `message` in the response: it must confirm that the deal is set as default. Use only deals of your own affiliates. Make sure the deal is active and belongs to the affiliate you intend. If the deal has a closed older version but an active newer one, the active version becomes the default. The `affiliate_id` field is used only for the activity log and does not select the affiliate.
{% endhint %}

## Getting a list of deals for the affiliate

You can use the HTTP GET method to get a list of all deals for the affiliate

```bash

curl --location 'https://boapi.smartico.ai/api/af2_deals_op?affiliate_id=100508' \
--header 'authorization: your-api-key'

```

You need to pass affiliate\_id; as a response, you will get a list of all deals, including the sub-deals.

When the commission, qualifiers or criteria of a deal change, TAP creates a new version of the deal. The old version stays in the list with `is_latest: false` and a `close_date`. To get only the current versions, add `is_latest=true`:

```bash
curl --location 'https://boapi.smartico.ai/api/af2_deals_op?affiliate_id=100508&is_latest=true' \
--header 'authorization: your-api-key'
```

In the deal fields:

* `deal_original_id` is the ID of the deal. It stays the same in all versions. The **ID** column of the **Deals** tab in the back office shows it.
* `deal_id` (and `id`) is the ID of one version (**Deal ID (version)** in the back office).
* `deal_parent_original_id` is the `deal_original_id` of the parent deal. It is `null` for main deals.
* `is_default: true` marks the default (home) deal.
* In the criteria, `-1` and `"ANY"` mean "Any".

![The Deals tab of an affiliate: main deals, sub-deals and the Home deal](https://2789002490-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkbip9hFgRFwIv4mXJPnz%2Fuploads%2FW9zU4leHCteNie2QDUuG%2Ftap-affiliate-deals-list-9b652dd7-b23c30.jpg?alt=media)

Example of the response:

```json
[
    {
        "id": 93195,
        "affiliate_id": 100508,
        "deal_id": 93195,
        "deal_original_id": 93195,
        "deal_parent_original_id": null,
        "deal_group_name": "Default deal",
        "match_brand_ids": [
            -1
        ],
        "match_af_product_ids": [
            -1
        ],
        "match_countries": [
            "ANY"
        ],
        "match_source_ids": [],
        "match_campaign_ids": [
            -1
        ],
        "match_date_from": null,
        "match_date_till": null,
        "cpa_tiers_enabled": true,
        "cpa_tiers_structure": [
            {
                "step": 1,
                "amount": 2
            },
            {
                "step": 3,
                "amount": 4
            },
            {
                "step": 5,
                "amount": 6
            }
        ],
        "rev_share_tiers_enabled": 0,
        "rev_share_tiers_structure": [],
        "cpa_amount": 1,
        "rev_share_percentage": null,
        "cpl_amount": null,
        "qua_cpa_net_deposit": null,
        "qua_cpa_volume": null,
        "qua_cpa_activity_count": null,
        "qua_cpa_ftd": null,
        "qua_cpa_deposit": null,
        "qua_cpl_volume": null,
        "qua_rev_on_cpa_option": 0,
        "deal_type_id": 2,
        "is_default": true,
        "create_date": "2023-08-03T10:18:10.168Z",
        "close_date": null,
        "create_by": 2342,
        "deduct_chargeback": true,
        "deduct_bonus": false,
        "no_negative_rs": false,
        "use_revshare_products": null,
        "revshare_product_percentages": null,
        "username": "admin",
        "is_latest": true,
        "admin_fee_perc": null,
        "late_conversion_days": null,
        "lifetime_revshare_days": null,
        "admin_fee_perc_op": null,
        "late_conversion_days_op": null,
        "lifetime_revshare_days_op": null,
        "level_id": 1,
        "match_readable_brands": "Any brand",
        "match_readable_countries": "Any country",
        "match_readable_other": "",
        "cpa_tier_step_1": 1,
        "cpa_tier_amount_1": 2,
        "cpa_tier_step_2": 3,
        "cpa_tier_amount_2": 4,
        "cpa_tier_step_3": 5,
        "cpa_tier_amount_3": 6,
        "revshare_products": null
    },
    {
        "id": 94509,
        "affiliate_id": 100508,
        "deal_id": 94509,
        "deal_original_id": 94509,
        "deal_parent_original_id": 93195,
        "deal_group_name": null,
        "match_brand_ids": [
            -1
        ],
        "match_af_product_ids": [
            -1
        ],
        "match_countries": [
            "AX"
        ],
        "match_source_ids": [],
        "match_campaign_ids": [
            -1
        ],
        "match_date_from": null,
        "match_date_till": null,
        "cpa_tiers_enabled": true,
        "cpa_tiers_structure": [
            {
                "step": 1,
                "amount": 2
            },
            {
                "step": 3,
                "amount": 4
            },
            {
                "step": 5,
                "amount": 6
            }
        ],
        "rev_share_tiers_enabled": 0,
        "rev_share_tiers_structure": [],
        "cpa_amount": 5,
        "rev_share_percentage": null,
        "cpl_amount": null,
        "qua_cpa_net_deposit": null,
        "qua_cpa_volume": null,
        "qua_cpa_activity_count": null,
        "qua_cpa_ftd": null,
        "qua_cpa_deposit": null,
        "qua_cpl_volume": null,
        "qua_rev_on_cpa_option": 0,
        "deal_type_id": 2,
        "is_default": false,
        "create_date": "2023-08-06T08:29:50.555Z",
        "close_date": null,
        "create_by": 2342,
        "deduct_chargeback": true,
        "deduct_bonus": false,
        "no_negative_rs": false,
        "use_revshare_products": null,
        "revshare_product_percentages": null,
        "username": "admin",
        "is_latest": true,
        "admin_fee_perc": null,
        "late_conversion_days": null,
        "lifetime_revshare_days": null,
        "admin_fee_perc_op": null,
        "late_conversion_days_op": null,
        "lifetime_revshare_days_op": null,
        "level_id": 2,
        "match_readable_brands": "Any brand",
        "match_readable_countries": "AX",
        "match_readable_other": "",
        "cpa_tier_step_1": 1,
        "cpa_tier_amount_1": 2,
        "cpa_tier_step_2": 3,
        "cpa_tier_amount_2": 4,
        "cpa_tier_step_3": 5,
        "cpa_tier_amount_3": 6,
        "revshare_products": null
    }
]
```

The player counts of each deal (`cpl_users_count`, `cpa_users_count`, `rev_users_count`) are not returned when you call with an API key.

If you are interested only in the current root level deals, call with `is_latest=true` and take only deals with level\_id: 1


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.theaffiliateplatform.com/apis-and-configurations/deals-management-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
