# User Level Reporting API

The User Level Reporting API enables you to access reporting data to measure all revenue generated from individual users. This information can be used to optimize retargeting campaigns and accurately measure user lifetime value.

You can query revenue and impressions metrics across the available dimensions. For all supported metrics and dimensions for the User Level Reporting API, click the Metrics and Dimensions tab above.

{% hint style="info" %}
The User Level Reporting API is disabled by default for any new app onboarding. To enable it, contact your Account Manager. Once enabled, data is aggregated from six days prior to the activation date.
{% endhint %}

## Reporting API Workflow <a href="#reporting-api-workflow-0-1" id="reporting-api-workflow-0-1"></a>

The publisher makes a POST request using the Client ID and Client Secret to receive the Access Token, as described in [Step 1](#h_01g4hmkwpcr5rxh0tjm3ekt9cf).

Once the request is successful and the Access Token is received, an API Request is made to create a custom report as described in [Step 2](#h_01g4hmmgmv8hcpfj19m0wn6vvv).

A successful response will contain a URL leading to a file containing the custom report. More details can be found in [Step 3](#step-3-receiving-the-custom-report-0-21).

## Step 1: Obtaining the Access Token <a href="#h_01g4hmkwpcr5rxh0tjm3ekt9cf" id="h_01g4hmkwpcr5rxh0tjm3ekt9cf"></a>

Digital Turbine's Reporting API uses Access Tokens for authentication purposes. To obtain your Access Token, you must first get your Client ID and Client Secret.

Obtaining your Client ID and Client Secret

1. Sign in to the [DT Console](https://console.fyber.com/login).
2. On the top left side of the screen click your User ID

<div align="left" data-with-frame="true"><img src="https://1641760969-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KSLu5HNiyDWpvGRZh7B%2Fuploads%2FwsKPp5G64KmflX1mSVL2%2Fimage.png?alt=media&#x26;token=df8c5a31-7d13-4bbd-8b3b-d4f944125257" alt="" width="209"></div>

3. Click User Profile to display the Reporting API Keys

<div align="left" data-with-frame="true"><img src="https://1641760969-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KSLu5HNiyDWpvGRZh7B%2Fuploads%2FznPObyxLPssjTCoAwIlK%2FScreen_Shot_2022-08-23_at_14_34_10.png?alt=media&#x26;token=1b5b4a35-4ebd-4af9-81f4-d0dc874933b2" alt=""></div>

4. If necessary, you can click **Revoke** to delete the current credentials.\
   You are returned to the API Keys window.

<div align="left" data-with-frame="true"><img src="https://1641760969-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KSLu5HNiyDWpvGRZh7B%2Fuploads%2F4oyDWnkpgEglQ1Pabb7U%2FScreen%20Shot%202022-08-23%20at%2014.34.42.png?alt=media&#x26;token=99af5ead-c231-45cc-95f0-69d20cda02b9" alt="" width="375"></div>

5. Click **Generate New Keys** again, to receive new credentials.

{% hint style="info" %}
Keep your Client ID and Client Secret safe, as they can be reused in the future.
{% endhint %}

Using your Client ID and Client Secret make a POST request to receive your Access Token.

The base End Point for the entire process is: `https://reporting.fyber.com`

#### Authentication token <a href="#authentication-token-0-2" id="authentication-token-0-2"></a>

```
POST /auth/v1/token
```

#### Headers <a href="#headers-0-3" id="headers-0-3"></a>

```
Content-Type    application/json
```

#### Sample Request <a href="#sample-request-0-4" id="sample-request-0-4"></a>

```
https://reporting.fyber.com/auth/v1/token
```

#### Params <a href="#params-0-5" id="params-0-5"></a>

```
format  csv
```

#### Body: raw (application/json) <a href="#body-raw-application-json--0-6" id="body-raw-application-json--0-6"></a>

{% code title="JSON" %}

```json
{
    "grant_type": "client_credentials",
    "client_id": "3ce66d885XXXXXXXXXXa3b752bb9058",
    "client_secret": "YtMvC7VYTQMQ7w9UCUaFXXXJnwVZnQqqN02XNyt8IIh2h8XFDuXXXXXXXXSS6XTrFWW4TkebCcMLJkrXSw5IurkearTJIDzUxsbiMXv8hb4T23MwN6eE7DDIthRFqDnhnuhiDlY2oPeaOjsMbzE8joZ5cs6tsySJz6uZXwJ-x3lcYaYbgXXXXXXXX3_hFeuXm-C7-me2V1MMs-ftJxTd5QbHoUhG3Q5anCWCW_pg8x3CL4yPGCbpWUDZfpdNPyyCT4rxCEb-VC0Bdqwe8N2GGn_VSFOwQYxa-yap2JuNSGJfl_ZURXXXXXXXXFe1GpHDn8pk7yYwQYIGAg"
}
```

{% endcode %}

* **Grant Type** must be "client\_credentials"
* The credentials are sent according to the OAuth 2.0 protocol

### Sample Authentication Response <a href="#sample-authentication-response-0-7" id="sample-authentication-response-0-7"></a>

When an authentication request is successful, you receive the following response in JSON format:

#### Successful Response <a href="#successful-response-0-8" id="successful-response-0-8"></a>

{% code title="JSON" %}

```json
{
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXXXJ9.eyJpYXQiOjE1NzAwMTY5MDAsImV4cCI6MTU3MDAyMDUwMCwiYXVkIjoic3BlZWRiYWxsIiwic3ViIjoiMjEwMjYzIn0.hDo1waTytSys_oRhFNUPqZPom26bL05rxgtSt3XYHqI",
  "tokenType": "bearer",
  "expiresIn": 3600
}
```

{% endcode %}

| Parameter     | Description                                |
| ------------- | ------------------------------------------ |
| `accessToken` | The token required to continue the process |
| `tokenType`   | Bearer                                     |
| `expiresIn`   | 3600 seconds (1 hour)                      |

When a request is unsuccessful, you receive the following response:

#### Unsuccessful Response <a href="#unsuccessful-response-0-9" id="unsuccessful-response-0-9"></a>

{% code title="JSON" %}

```json
{
  "error": "internal_server_error"
}
```

{% endcode %}

### Possible Authentication Errors <a href="#possible-authentication-errors-0-10" id="possible-authentication-errors-0-10"></a>

Set out in the table are a list of possible errors which resulted in an unsuccessful response.

| HTTP Status Code | Error                    | Scenario                                                                                                                                                               |
| ---------------- | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 400              | unsupported\_grant\_type | N/A                                                                                                                                                                    |
| 400              | invalid\_request         | When there are missing credentials                                                                                                                                     |
| 400              | invalid\_client          | <p>When the credentials are incorrect or cannot be recognized.<br>Can also occur when your account has been disabled or when the credentials<br>have been revoked.</p> |
| 500              | internal\_server\_error  | Unexpected errors in DT's servers                                                                                                                                      |

## Step 2: Reporting API Request <a href="#h_01g4hmmgmv8hcpfj19m0wn6vvv" id="h_01g4hmmgmv8hcpfj19m0wn6vvv"></a>

Use the access token you received in Step 1 to request your custom report.

The two dimensions that you can query in your request are:

* Date
* App ID

All other dimensions always appear in the report.

### Request Example <a href="#request-example-0-12" id="request-example-0-12"></a>

The below is an example from the User Level report.

#### Date <a href="#date-0-13" id="date-0-13"></a>

Date: 2020-16-02\
AppID: 123

For a full list of supported Metrics and Dimensions, see [User Level Metrics and Dimensions](#user-level-data-0-26).

For further descriptions about the terms used in this article, see [Using the Reports](https://app.gitbook.com/s/LbREhkP3WlLtP6TNVZ2Q/reports/using-the-reports).

Make a POST request to receive your report.

#### URL <a href="#url-0-14" id="url-0-14"></a>

```
https://reporting.fyber.com/api/v1/report/user-level-data
```

#### Headers <a href="#headers-0-15" id="headers-0-15"></a>

```
Content-Type:   application/json
Authorization: Bearer <Access Token from Authentication Response>
```

#### Body. raw (application/json) <a href="#body-raw-application-json--0-16" id="body-raw-application-json--0-16"></a>

{% code title="JSON" %}

```json
{
    “date”: "2020-01-01",
    “appId”: “123"
}
```

{% endcode %}

### Responses <a href="#responses-0-17" id="responses-0-17"></a>

Set out below are examples of both successful and unsuccessful responses.

#### Response: Successful <a href="#response-successful-0-18" id="response-successful-0-18"></a>

{% code title="JSON" %}

```json
{
  "id": "6fad42cb-25db-4af0-8988-1e7d8e6d90bc",
  "url": "https://fyber-async-reports.s3.amazonaws.com/group%3D210263/6fad42cb-25db-4af0-8988-1e7d8e6d90bc.csv?AWSAccessKeyId=AKIAQBQNZ5FY23OTK4UD&Expires=1570020564&Signature=LbhE5uljlPEKQRTbepDqmDgJuFQ%3D",
}
```

{% endcode %}

* The "id" field holds an identifier of the request for later troubleshooting, if required.
* The "url" field holds the URL to be polled (GET request) until the body response (file) is populated.

#### Response: Unsuccessful <a href="#response-unsuccessful-0-19" id="response-unsuccessful-0-19"></a>

{% code title="JSON" %}

```json
{
  "error": "invalid_token"
}
```

{% endcode %}

### Possible Errors <a href="#possible-errors-0-20" id="possible-errors-0-20"></a>

The table below shows the main errors indicating an unsuccessful response.

| HTTP Status Code | Error                   | Description (optional)                                                                                                                                                              | Scenario                                                                                                                                                                |
| ---------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 401              | invalid\_token          | N/A                                                                                                                                                                                 | <p><em>Authorization header is empty</em><br>Authorization header not sent or token is not present in the header<br><em>Unrecognized token</em><br>Disabled account</p> |
| 400              | invalid\_query          | <p>For example:<br>Invalid value undefined supplied to : Query/dateRange: DateRange<br><br>-or-<br><br>Invalid value "XXXXX" supplied to : Query/dateRange: DateRange/end: Date</p> | <p><em>If the query sent is not in the expected schema</em><br>Date range is not sent in the ISO 8601 format</p>                                                        |
| 500              | internal\_server\_error | N/A                                                                                                                                                                                 | Error in DT's servers                                                                                                                                                   |

## Step 3: Receiving the Custom Report <a href="#step-3-receiving-the-custom-report-0-21" id="step-3-receiving-the-custom-report-0-21"></a>

To obtain the Custom Report, follow the steps below:

1. Receive the URL from the successful response in [Step 2](#h_01g4hmmgmv8hcpfj19m0wn6vvv).
2. Click the link. You are redirected to a folder which contains your report.

{% hint style="info" %}
The URL is valid for three hours.
{% endhint %}

## Additional Information and Restrictions <a href="#additional-information-and-restrictions-0-22" id="additional-information-and-restrictions-0-22"></a>

It is important to take note of the information, restrictions and rules to ensure the reports provided to ensure a successful response.

### General <a href="#general-0-23" id="general-0-23"></a>

* All reports are presented in US dollars
* The time zone used is UTC
* The data in the folder is available by 1200 UTC (noon) for the previous 10 days.

### Query Restrictions <a href="#query-restrictions-0-24" id="query-restrictions-0-24"></a>

* All dimensions are mandatory.

### Date Information <a href="#date-information-0-25" id="date-information-0-25"></a>

There are a number of rules that must be observed with regard to the date:

* The date must be in the format of ISO 8601. For example, 2019-10-03
* The date is included in the report
* The date is relevant from 16 February 2020

You must specify in the API Request the metrics and dimensions you want to include in your custom report.

## User Level Metrics and Dimensions <a href="#user-level-data-0-26" id="user-level-data-0-26"></a>

Set out in the tables below are the supported metrics and dimensions available in the User Level Reporting API.

### Metrics <a href="#metrics-0-27" id="metrics-0-27"></a>

| Supported Metrics | Description                                      |
| ----------------- | ------------------------------------------------ |
| Impressions       | Number of times the ad is displayed to the users |
| Revenue           | The total revenue of the publisher in USD        |

Discrepancies may occur since the number of impressions is based on our counting method and revenues are estimated.

### Dimensions <a href="#dimensions-0-28" id="dimensions-0-28"></a>

The following are the supported Dimensions for the User Level Reporting API:

| Supported Dimensions | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Ad Network Name      | For mediation, we use the network name and for DT Exchange networks we use 'DT Exchange'                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Ad Unit ID           | The ad unit identifier in the DT system                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| Container Type ID    | The identifier of the type of placement                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| Advertising ID       | The Advertising ID for either Apple or Google                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| IDFV                 | An alphanumeric string that uniquely identifies a device to the app’s vendor. (This dimension is relevant to FairBid customers only).                                                                                                                                                                                                                                                                                                                                                                                                            |
| User ID              | The identifier of the user supplied by the publisher. (This dimension is relevant to FairBid customers only).                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| Instance ID          | The Instance ID as generated by the demand network. Note: This is referred to differently, by various demand networks.                                                                                                                                                                                                                                                                                                                                                                                                                           |
| Placement ID         | A Placement's identifier in the DT system                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Placement Type       | <p>Placement type describes how ads will look in your app and where ads will be located. Placement types can be either banner, interstitial or rewarded.<br><br><strong>Banner</strong><br><br>A basic placement type appearing at the top or bottom of the device's screen. Does not support video content<br><br><strong>Rewarded</strong><br>An ad placement type supporting video content<br><br><strong>Interstitial</strong><br>Full-page ads appear at natural breaks & transitions, such as level completion. Supports video content</p> |
