This API is a set of API services provided by Ads Kit for you to obtain traffic monetization report data, including the number of ad requests, number of returned ads, impression rate, click-through rate, and revenue proportion, implementing efficient report monitoring for each channel.
To call this API, you need to pass channel-specific parameters and ensure that a valid ad event has occurred when an ad request is initiated. For details about how to pass channel-specific parameters, please refer to Customizing Parameters for Channels.
To obtain channel-specific monetization data for your app, your app server can call this API.
| Protocol | HTTPS POST |
|---|---|
| Direction | Client -> Publisher Service Channel Report server |
| URL | POST https://ads.cloud.huawei.com/openapi/monetization/reports/v1/channelReport NOTE: URL for the Russia site: POST https://ads-drru.cloud.huawei.ru/openapi/monetization/reports/v1/channelReport |
| Data Format | Request: Content-Type: application/json Response: Content-Type: application/json |
Request Header
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Content-Type | Yes | String | The fixed value is application/json; charset=UTF-8. |
| Authorization | Yes | String | For details, please refer to OAuth 2.0-based Authentication. Note A space character must be added between Bearer and the value of access_token. |
Request Body
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| start_date | Yes | String | Start date. The format is yyyy-MM-dd. |
| end_date | Yes | String | End date. The format is yyyy-MM-dd. |
| app_ids | No | String[] | App ID. |
| bundles | No | String[] | App package name. |
| group_by | No | String[] | Grouping condition. Only grouping by date is supported. That is, STAT_BREAK_DOWNS_DATE needs to be passed. If a grouping condition is provided, the response data will be displayed on a daily basis. If no grouping condition is provided, the response data will be summarized. |
| page | No | Integer | Page number for search. The value ranges from 1 to 1000. The default value is 1. |
| page_size | No | Integer | Number of records displayed on each page. The value ranges from 1 to 1000. The default value is 20. |
| order_field | No | String | Sorting field. All statistical indicators can be sorted. |
| order_type | No | String | Sorting mode. The options are ASC and DESC. The default value is DESC. |
POST / openapi / monetization / reports / v1 / channelReport HTTP / 1.1
Content - Type: application / json
Authorization: Bearer * * *
Accept: application / json
Content - Length: 233 {
"start_date": "2024-03-20",
"end_date": "2024-06-20",
"group_by": ["STAT_BREAK_DOWNS_DATE"],
"page": 1,
"page_size": 10,
"order_field": "show_count",
"order_type": "DESC"
} Response Header
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Content-Type | Yes | String | The fixed value is application/json; charset=UTF-8. |
Response Body
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| code | Yes | String | |
| message | Yes | String | Return description. |
| data | No | struct | Statistical data of specified objects. For details, please refer to Parameters in data. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| page_info | Yes | struct | Pagination configuration information. For details, please refer to Parameters in page_info. |
| list | Yes | struct | Statistical data list. For details, please refer to Parameters in list. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| page | Yes | Integer | Page number for search. |
| page_size | Yes | Integer | Number of records displayed on each page. |
| total_number | Yes | Integer | Total number of data records. |
| total_page | Yes | Integer | Total number of pages. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| app_id | No | String | App ID. This parameter is meaningless without grouping by app. |
| channel_id | No | String | Channel ID. This parameter is meaningless without grouping by channel. |
| stat_datetime | Yes | String | Start time of data query. Format: yyyy-MM-dd |
| reached_ad_requests | No | Integer | Number of ad requests. |
| matched_reached_ad_requests | No | Integer | Number of returned ads. |
| show_count | No | Integer | Number of impressions. |
| click_count | No | Integer | Number of clicks. |
| ad_requests_match_rate | No | float | Fill rate. |
| ad_requests_show_rate | No | float | Impression rate. |
| click_through_rate | No | float | Click-through rate. |
| earning_rate | No | float | Estimated revenue proportion. |
HTTP / 1.1 200 OK
Content - type: application / json
content - length: 2381 {
"code": "0",
"message": "OK",
"data": {
"page_info": {
"page": 1,
"page_size": 1,
"total_number": 1,
"total_page": 1
},
"list": [{
"app_id": "1111111",
"channel_id": "1",
"stat_datetime": "2024-05-01",
"earnings": 30.8,
"reached_ad_requests": 100,
"matched_reached_ad_requests": 90,
"show_count": 154,
"click_count": 14,
"ad_requests_match_rate": 0.8256,
"ad_requests_show_rate": 0.2121,
"click_through_rate": 0.2141,
"earning_rate": 0.2141
}
]
}
} Send an HTTPS POST request using the client ID and key obtained from HUAWEI Developers to obtain an access token.
The Java sample code is as follows:
The value of tokenUrl is https://oauth-login.cloud.huawei.com/oauth2/v3/token.
/**
* Obtain the access token.
*
* @return Return the token value.
* @throws IOException Exception.
*/
private static String getOauthToken() throws IOException {
// Set the packet header Content-Type.
PostMethod postMethod = new PostMethod(tokenUrl);
postMethod.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded;charset=utf-8");
// Set the packet body.
List < NameValuePair > param = new ArrayList < > ();
param.add(new NameValuePair("grant_type", "client_credentials"));
param.add(new NameValuePair("client_id", clientId));
param.add(new NameValuePair("client_secret", secret));
postMethod.setRequestBody(param.toArray(new NameValuePair[param.size()]));
HttpClient httpClient = new HttpClient();
int ret = httpClient.executeMethod(postMethod);
String accessToken = null;
String tokenResponse = postMethod.getResponseBodyAsString();
if (ret == 200) {
JSONObject atJson = JSONObject.parseObject(tokenResponse);
accessToken = atJson.getString("access_token");
} else {
System.out.println("request access token failed " + tokenResponse);
}
return accessToken;
} Send an HTTPS POST request with the obtained access token to query report data.
The Java sample code is as follows:
The value of reportUrl is https://ads.cloud.huawei.com/openapi/monetization/reports/v1/channelReport.
/**
* Call the Publisher Service Reporting API.
* @param accessToken Token obtained based on the client ID and key.
* @throws IOException
*/
private static void callApiUseToken(String accessToken) throws IOException {
// Set the packet headers Content-Type and Authorization.
PostMethod postMethod = new PostMethod(reportUrl);
postMethod.setRequestHeader("Content-Type","application/json;charset=utf-8");
postMethod.setRequestHeader("Authorization","Bearer " + accessToken);
// Set the packet body.
Map<String, Object> bodyMap = new HashMap<>();
bodyMap.put("start_date", "2024-05-01");
bodyMap.put("end_date", "2024-06-20");
bodyMap.put("order_field", "show_count");
bodyMap.put("order_type", "DESC");
RequestEntity requestEntity = new StringRequestEntity( JSONObject.toJSONString(bodyMap),
"application/json" ,"UTF-8");
postMethod.setRequestEntity(requestEntity);
HttpClient httpClient = new HttpClient();
int ret = httpClient.executeMethod(postMethod);
String rpsContent = postMethod.getResponseBodyAsString();
if (ret == 200) {
System.out.println(rpsContent);
} else {
System.out.println("callApi failed: ret =" + ret + " rsp=" + rpsContent);
}
}