FORUMS

HUAWEI Analytics Kit: Data Export

1,035 posts
Thanks Meter: 1,119
 
By XDARoni, XDA Community Manager on 30th June 2020, 06:04 PM
Post Reply Email Thread
Use Cases
HUAWEI Analytics Kit provides a server API for you to export event data collected on devices and import the data to your BI system for unified data analysis. After the export is complete, Analytics Kit asynchronously uploads the exported data to the Object Storage Service (OBS) and then returns the export result and data storage path to your app server by sending an HTTPS POST request to call its callback API. To ensure data security, the download link will become invalid after 2 hours.

The following table describes the export states that are currently supported.


The following table lists the data filter criteria.


Getting Started
Setting the Callback API
Sign in to AppGallery Connect. Go to My projects > HUAWEI Analytics > Management > Analysis setting, and select Set Callback API to set related parameters.



1. Configure the callback API URL for receiving the data download link.
2. Configure the HTTPS certificate.
3. Click Test callback to test the function of the callback API. After the test is successful, click Submit to complete the callback API configuration.

Development Guide
Before developing a callback API, you need to prepare a public network domain name and an API that can receive POST requests. Ensure that the POST API has an HTTPS certificate.

The development procedure is as follows:
1. Develop the callback API. In the sample code, the domain name is habackup.hwcloudtest.cn, which is accessible by your server.
Code:
@RequestMapping(value = "/agc/analytics/callback", method = RequestMethod.POST)
public ResultResp callback(@RequestBody @Valid ExportDataCallbackReq req) {
    ResultResp result = new ResultResp();
     // Receive the callback after the export task is generated.
    if (LOGGER.isDebugEnabled()) {
       LOGGER.debug("the download url: {}", req.getFilePath());
    }
    // Obtain the download link to continue.
    result.setResultCode("0");
    result.setResultMsg("success");
    return result;
}
Requested object:
Code:
public class ExportDataCallbackReq implements Serializable {
    private static final long serialVersionUID = -8014011591749838257L;
    @JsonProperty("request_id")
    private String requestId;
    @JsonProperty("app_id")
    private String appId;
    @JsonProperty("status")
    private String status;
    @JsonProperty("file_path")
    private String filePath;
    @JsonProperty("status_time")
    private String statusTime;
}
2. Go to HUAWEI Analytics > Management > Analysis setting to configure the callback API.

3. Call the public API to obtain the token
POST request:
URI: https://oauth-login.cloud.huawei.com/oauth2/v2/token
Header:
Code:
Content-Type:Application/x-www-form-urlencoded
Body:
Code:
grant_type:client_credentials
client_id:100664247
client_secret:170e4ecb457bd73fa7c977de976274a7
Response:
Code:
{
  "access_token": "CV6qeoJReXe+YfDRQomDe9VW1B6fzIH1QU260T94x4RBLUSZRjTRIcY7IngF1cPIEYaPhJCjVNOxrhvAo49Ay/Ukkf+p",
  "expires_in": 3600,
  "token_type": "Bearer"
}
4. Start data export.
POST request:
URI: https://datacollector-drcn.dt.hiclou...ta_requests/v2
Header:
Code:
Authorization:Bearer CV6qeoJReXe+YfDRQomDe9VW1B6fzIH1QU260T94x4RBLUSZRjTRIcY7IngF1cPIEYaPhJCjVNOxrhvAo49Ay\/Ukkf+p (token_type + space + access_token, obtained from the token response)
x-App-id:10066424
Content-Type:Application/json
x-product-id:9105163812218569643
Body:
Code:
{
  "date_range": {
    "start_date": "2020-2-29",
    "end_date": "2020-3-10"
  },
  "file_format": "csv",
  "filters": []
}
Response:
Code:
{
  "result_code": "0",
  "result_msg": "success"
}
5. View the export status.
Go to My projects > HUAWEI Analytics > Management > Data export.

6. After the export is complete, the Analytics Kit automatically calls the callback API to obtain the export result. Obtain the download link from the file_path field. The link is effective in 6 hours.
7. View the export result. If the following information is displayed, the export is successful.
Code:
[
  {
    "request_id": "c0b41debe8064c54ab200d30907f40c5",
    "App_id": "100664247",
    "status": "EXPORTED",
    "file_path": "https://nsp-ha-gdpr-drcn.obs.cn-north-2.myhuaweicloud.com/20200430_14_c0b41debe8064c54ab200d30907f40c5.csv?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=F9WBKUUWDQODJO4FQMBF%2F20200430%2Fcn-north-2%2Fs3%2Faws4_request&X-Amz-Date=20200430T073623Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=9145e80d51e21cd295861a5a0688bbcfbf8805e071cd8b98e08b5eacf2171fdb",
    "status_time": "2020-04-30 07:37:02"
  }
]
For details about the fields int he exported file, please refer to Description of Fields in the Export Data File.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes