# 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 %}

## Creating new deals for affiliates

The operator can use the HTTP POST method to build deals for specified affilite\_id.

The platform supports the following deals:&#x20;

```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,
}
```

To create a new deal for an affiliate, you need to make an HTTP POST request to the API endpoint with the following JSON body.

```jsonp

{
    "affiliate_id": 64257,
    "deal_type_id": 2, // One of deal types
    "deal_group_name": "Some name of the deal",
    
    // 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 CPA 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
    
    // parameters for setting the deal criteria
    "match_brand_is": [123],   // optional, if not passed, deal will be applicable for 'Any Brand'

        
}
```

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.

The API key to access the end-point is the same as described [here](/apis-and-configurations/reporting-api.md#obtaining-api-key-for-affiliate)

Example of the call that creates a CPA + RevShare\_NetPL deal with&#x20;

* 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 platform BackOffice.

<figure><img src="/files/OsXOHNIYVTyn6YbFljxQ" alt=""><figcaption><p>10 CPA with 25 FTD Qualifier, 25% rev share</p></figcaption></figure>

## Set default deal for affiliate<br>

You can use the HTTP POST method to set a default deal for the affiliate.\
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' \
--header 'Active_label_id: 12345' \
--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" }
```

## 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. 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_amount": null,
        "deal_type_id": 2,
        "is_default": true,
        "create_date": "2023-08-03T10:18:10.168Z",
        "close_date": null,
        "create_by": 2342,
        "is_latest": true,
        "cpl_users_count": "0",
        "cpa_users_count": "0",
        "rev_users_count": "0",
        "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
    },
    {
        "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,
        "rev_cap_amount": 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_amount": null,
        "deal_type_id": 2,
        "is_default": false,
        "create_date": "2023-08-06T08:29:50.555Z",
        "close_date": null,
        "create_by": 1,
        "is_latest": true,
        "cpl_users_count": "0",
        "cpa_users_count": "0",
        "rev_users_count": "0",
        "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
    }
]
```

If you are interested only in the root level deals, you will need to take only deals with level\_id: 1


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
