# Reporting API

{% hint style="info" %}
This document describes how to get affiliation metrics via API (commission, balance, registrations, etc.).

It can be used by the Operator - to get metrics for all affiliates.

Or it can be used by the Affiliate - to get only their own metrics.
{% 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.\
\
\&#xNAN;***If you are an affiliate***, check for the exact URL in '**Account Settings**' section in your profile.
{% endhint %}

TheAffiliatePlatform (TAP) provides API to retrieve configurational, operational, and analytical data. API is provided as a REST over HTTP and uses SSL for data protection.

Reporting API is designed for the high level aggregated reporting (aggregated overview per operation/affiliate and not per individual user).

Affiliates can use API to get reports related to the activities of their own traffic and for the Operator to have access to all affiliates' data.

## **API for the Affiliate**

### Accessing analytical data

The Affiliation system has an API endpoint that provides statistical information about visits, registrations, commissions, etc., aggregated by a specified period or for a lifetime.

Example of the API call using CURL:

{% code overflow="wrap" %}

```bash
curl --location --request GET 'https://boapi.smartico.ai/api/af2_media_report_af?aggregation_period=DAY&group_by=utm_campaign,utm_medium,utm_source,afp&date_from=2022-07-12&date_to=2022-07-14' --header 'authorization: your_api_key'
```

{% endcode %}

Example of API call using NodeJs:

```javascript
var request = require('request');
var options = {
 'method': 'GET',
 'url': 'https://boapi.smartico.ai/api/af2_media_report_af?aggregation_period=DAY',
 'headers': {
   'authorization': 'your_api_key'
 }
};
request(options, function (error, response) {
 if (error) throw new Error(error);
 console.log(response.body);
});

```

Parameters in API call:

* As **aggregation\_period** you can pass DAY, MONTH, YEAR, or keep it empty in order to get aggregate data for the lifetime.&#x20;
* Optional parameter group\_by could have a comma-separated list of the fields to group results. Possible values are:&#x20;
  * utm\_campaign
  * utm\_medium
  * utm\_source
  * afp, afp1, afp2.... afp9
  * link\_id
  * brand\_id
  * campaign\_id
  * source\_id
  * deal\_root\_original\_id
  * registration\_id (requires "Registrations report" permissions)
  * ext\_customer\_id (requires "Registrations report" permissions)
  * username (requires "Registrations report" permissions)
* Optional parameters **date\_from** and **date\_to** could be used to limit results for the defined period. The format of the date is YYYY-MM-DD

{% hint style="danger" %}
Important note regarding setting date\_from and date\_to parameters.&#x20;

* date\_from is inclusive
* date\_to is exclusive

This means that for the request with date\_from = 2022-07-12 and date\_to=2022-07-14, API will return data for 12 and 13 July only.<br>

* `date_from` and `date_to` must always be used **together** -  either provide both parameters or omit both. Providing only one of them is not supported.
  {% endhint %}

Example of response:

```json
 
{
   "meta": {
       "affiliate_id": 34598,
       "operator_currency": "EUR",
       "operator_public_name": "Supper Affiliate",
       "operator_bo_domain": "https://admin.aff.smartico.ai/",
       "operator_image_url": "https://static.smartico.ai/73a6af827f2162f79c7996-cropped-FBLogo.png"
   },
   "data": [{
       "dt": "2020-08-01T00:00:00.000Z",
       "link_id": "29",
       "link_name": "test redirect",
       "brand_id": "5",
       "brand_name": "XP",
       "visit_count": 4,
       "registration_count": 24,
       "qftd_count": 0,
       "qlead_count": 0,
       "deposit_count": 2,
       "deposit_total": 40,
       "net_deposits": 20,
       "net_pl": 70,
       "net_win": 100,
       "pl": 100,
       "net_pl_sport": 30
       "net_pl_casino": 40
       "ftd_count": 2,
       "ftd_total": 40,
       "bonus_amount": 30
       "withdrawal_count": 1,
       "withdrawal_total": 20,
       "chargeback_total": 0,
       "operations": 5,
       "volume": 10,
       "commissions_cpl": 0,
       "commissions_cpa": 0,
       "commissions_rev_share": 5,
       "deductions": 0,
       "sub_commission_from_child": 0,
       "adjustment_affiliate": 0,
       "adjustment_registration": 0,
       "payments": 0,
       "conversion_rate": 0.08333332986111125,
       "net_deposit_total": 20,
       "commissions_total": 5,
       "adjustments": 0,
       "balance": 5
   }, {
       "dt": "2020-07-01T00:00:00.000Z",
       "link_id": "4",
       "link_name": "Test/XPK-Registration",
       "brand_id": "5",
       "brand_name": "XP",
       "visit_count": 7,
       "registration_count": 0,
       "qftd_count": 0,
       "qlead_count": 0,
       "deposit_count": 0,
       "deposit_total": 0,
       "net_deposits": 30,
       "net_pl": 40,
       "net_win": 80,
       "pl": 80,
       "net_pl_sport": 25
       "net_pl_casino": 15
       "ftd_count": 0,
       "ftd_total": 0,
       "bonus_amount": 40,
       "withdrawal_count": 0,
       "withdrawal_total": 0,
       "chargeback_total": 0,
       "operations": 2,
       "volume": 20,
       "commissions_cpl": 0,
       "commissions_cpa": 0,
       "commissions_rev_share": 0,
       "deductions": 0,
       "sub_commission_from_child": 0,
       "adjustment_affiliate": 0,
       "adjustment_registration": 0,
       "payments": 0,
       "conversion_rate": 0,
       "net_deposit_total": 0,
       "commissions_total": 0,
       "adjustments": 0,
       "balance": 0
   }]
}

```

<figure><img src="https://lh6.googleusercontent.com/X8R5M7yv2UPvLzfsYZggeFtLKPZiv9C0uyT7dIzHzA5ZSTLqyqpXjIR6Zrdi508rQBCDYYBjMAiPnq0ZyxMLBwvemx4sjOWe7uPL-isbr-fDHTE9hObgIE6wjCCD9wvQ7ZbTlPsdQozWliDzZwmVyxs4aFTGr8K-b7CRMMBV4MyY2OnjdfsOaYgy" alt=""><figcaption><p>Report in the UI</p></figcaption></figure>

## API for the Operator

### Accessing analytical data

Operator API is similar to the Affiliate API.<br>

Example of the API call using CURL:

{% code overflow="wrap" %}

```bash
curl --location --request GET 'https://boapi.smartico.ai/api/af2_media_report_op?aggregation_period=DAY&group_by=utm_campaign,utm_medium,utm_source,afp&date_from=2022-07-12&date_to=2022-07-14' --header 'authorization: your_api_key'
```

{% endcode %}

The difference between APIs:

<table><thead><tr><th width="188">.</th><th>Affiliate API</th><th>Operator API</th></tr></thead><tbody><tr><td>Method name</td><td>af2_media_report_af</td><td>af2_media_report_op</td></tr><tr><td>Possible values for group_by parameter</td><td>afp(1..9), utm_campaign, utm_medium', utm_source, link_id, brand_id, source_id, campaign_id, registration_id, ext_customer_id, username</td><td>affiliate_id, registration_id, ext_customer_id, username, afp(1..9), utm_campaign, utm_medium, utm_source, link_id, brand_id, campaign_id, source_id, deal_root_original_id,  child_affiliate_id, manager_id</td></tr><tr><td>Possible values for filtering data</td><td>date_from, date_to</td><td>date_from, date_to, affiliate_id, brand_id</td></tr></tbody></table>

## **Important to know**

* All amounts are in operator currency
* As TAP is providing an affiliation system as a white-label solution, you can find the name, domain, and image of the “Operator” operating affiliation system in response to API calls.
* In grouping by "day",  the report will show the change of commission during this day. It's not a total commission at the end of the day.
* If you are querying aggregated data and there are no activities for a specific period, the record for a specific period will be missing in response.\
  **Note that not all attributes are available for every affiliate. Visibility depends on the Additional Permissions granted to each Affiliate**
* If you query for aggregated data, the response will show only changes for a specified period. Given the example in the image below, you should treat it in the following way:&#x20;
  * During July, the affiliate had a change of balance “-795.50 EUR”, and because it was his first month, at the end of the month, his balance will be -795.50 EUR
  * During August, he had a positive change, +225 EUR. This means that his balance was “-570.50 EUR at the end of August.”
* "manager\_id" value can be passed as 123 or as 123,456

<figure><img src="https://lh3.googleusercontent.com/19n6WKNHzrea_cVwHxqVDlLcP5_IQC74p2iYZpUxXVuhVsQk-aAanObQ-8YJQHfQs1mnrqMEknE43B02WikAUegu1oXdNq-Qzg3o4MLZLWXVzMtznsvkp9eolz6m30lE2a-U7wLZ41RbA6-5VBDPiU-MVisKt1t8Qy6jTuygxmXqoiVV48iDofSI" alt=""><figcaption><p>Example of rolling change of balance</p></figcaption></figure>
