目录

FAQs

REST

[h2]What should I do if the "Invalid Credentials" message is returned when I call an API?

This message will be returned if the API is being called with an invalid token. Perform the following to troubleshoot:

  1. Verify that the OAuth 2.0-based authorization mode has been used to request the token.
  2. Verify that you have strictly followed the standard procedure when applying for the token.
  3. Check whether the token has expired.

[h2]In which cases will the refresh token expire and how should I handle such a situation?

  1. The refresh token (RT) is not permanently valid. Currently, it is valid for six months. The validity period is not directly returned in the API and this may change in the future. When using AT (access token) to replace RT, saving the new RT can effectively reduce the chance of RT going invalid.

  2. The refresh token immediately expires in any of the following instances:

    • Password change
    • Account freeze
    • Account change or deletion
    • Account deregistration
    • Device deletion due to the number limit or by the user
    • Exit from the phone client APK (device)
    • Exit from the current browser
    • Exit from all browsers

If the refresh token expires, the result code 1203 will be returned when the access token is updated, with the sub-code being 11205 or 31204. For details, refer to Errors and Troubleshooting. You must mark the refresh token as expired. The user will then need to reauthenticate and reauthorize upon future sign-in.

[h2]What should I do if error "403: Insufficient Permission: Request had insufficient authentication scopes." is returned during API calling?

This error is reported due to lack of scopes. Make sure that you have obtained the corresponding scopes before performing any operations on user data via Health Service Kit.

The data that your app can access is both approved by Health Service Kit and granted by users.

Possible causes:

1. You have not applied for relevant scopes via the Health Service Kit card in the Console of HUAWEI Developers.

2. The appId you entered for generating the authorization code is different from the appId generated when you applied for scopes via the Health Service Kit card.

3. Users did not select relevant scopes during authentication.

Solution:

1. Check whether the appId entered for generating the authorization code has been used for applying for Health Service Kit scopes via the Health Service Kit card on the Console of HUAWEI Developers. If not, apply for OAuth scopes according to the data type guide by referring to Applying for Health Service Kit.

2. Check whether the appId you entered for generating the authorization code is the same as the appId generated when you applied for scopes via the Health Service Kit card.

3. Check whether the access token (AT) of the current user has granted relevant scopes. To do so, call the API for querying authentication information, and check the scope field in the response body.

[h2]What should I do if error "403: The query time is out of range." is returned when the exercise record query API is called?

To protect user data, you are only allowed to query data generated after user authorization. For example, if a user authorizes your app on February 14, 2022, data generated before February 14, 2022 will be unavailable to your app.

To query data generated before user authorization, you need to obtain the scope to read historical data.

If the query time is earlier than the available time range, the query fails and error code 403 is returned. For details, please refer to Reading Historical Data.

[h2]Why is a "400 Bad Request invalidArgument" message returned when the configurations are correct?

This message indicates that the parameters in the request are incorrect. If the URL contains user-specified request parameters, check whether the input parameters meet the parameter specifications. If the request body exists, check whether the format and type of the corresponding parameters meet the parameter requirements.

[h2]The response code of my request to create a subscription record is "400", "Bad Request", or "Failed to connect to the URL". Why?

Test the connectivity of your app's subscription callback URL, and check whether the HTTP response code of the URL is 204. To do this, sign in to HUAWEI Developers, click the Health Service Kit card, and find your app. Click Manage and then Test Connectivity. If the URL is accessible, message "The connectivity test is successful." will display. Then, you can call the API for creating a subscription record.

[h2]What should I do if an "Application package name (xxx) provided by un-trusted source." message is returned when creating data?

The app name you are using has not yet been registered on HUAWEI Developers. Please go to the HUAWEI Developers website and submit a registration request. This issue should be resolved after your request is approved.

[h2]How should I deal with the 403 HTTP status code with error code 121001?

Cross-site requests (for example, a user registered in Europe tries to request data in China) will be denied by Health Service Kit. In this case, you will receive a 403 HTTP status code, with the error code 121001. Error information returned in the response body is listed below. In the response header, you'll find Location with the domain name of Health Service Kit to be redirected to obtain data. Make sure that you re-initiate a request using the domain name in the response header, in compliance with the personal data privacy clauses in the Health Service Kit developer agreement.

{
  "error": {
    "code": 121001,
    "message": "request forbidden due to site cross"
  }
}

The following takes a user registered in Europe requesting to obtain step statistics from Health Service Kit in China as an example.

Request example (see the API for querying sampling data statistics for details)

POST
https://health-api.cloud.huawei.com/healthkit/v2/sampleSet:polymerize

Request body

Content-Type: application/json
Authorization: Bearer ***
x-client-id: ***
x-version: ***
x-caller-trace-id: ***
{
 "polymerizeWith": [
  {
   "dataTypeName": "com.huawei.continuous.steps.delta"  
  }
 ],
 "endTime": 1590422399000,
 "startTime": 1590336000000,
 "groupByTime": {
     "groupPeriod": {
         "unit": "day",
         "value": 1,
         "timeZone": "+0800"
    }
  }
}

Response body

HTTP/1.1 403 ACCESS FORBIDDEN
Content-type: application/json;charset=utf-8
Location: https://health-api.cloud.huawei.eu/healthkit/v2/sampleSet:polymerize
{
  "error": {
    "code": 121001,
    "message": "request forbidden due to site cross"
  }
}

Re-initiate a request using Location in the response header

POST
https://health-api.cloud.huawei.eu/healthkit/v2/sampleSet:polymerize

Request body

Content-Type: application/json
Authorization: Bearer ***
x-client-id: ***
x-version: ***
x-caller-trace-id: ***
{
 "polymerizeWith": [
  {
   "dataTypeName": "com.huawei.continuous.steps.delta"  
  }
 ],
 "endTime": 1590422399000,
 "startTime": 1590336000000,
 "groupByTime": {
     "groupPeriod": {
         "unit": "day",
         "value": 1,
         "timeZone": "+0800"
    }
  }
}

Response body

HTTP/1.1 200 OK
Content-type: application/json;charset=utf-8
x-health-app-privacy: 1
{
    "group": [
        {
            "startTime": 1590336000000,
            "endTime": 1590422399000,
            "sampleSet": [
                {
                    "dataCollectorId": "ZGVyaXZlZDpjb250aW51b3VzLnN0ZXBzLnRvdGFsEwMTI3ODUwMTpqEF7rB3uBcGykpv6T2TisfTMhfZAvz1BP2Kcz70d1Sg",
                    "samplePoints": [
                        {
                            "startTime": 1590373495000000000,
                            "endTime": 1590377095000000000,
                            "dataTypeName": "com.huawei.continuous.steps.total",
                            "originalDataCollectorId": "cmF3OmNjb250aW51b3VzLnN0ZXBzLmRlbHRhEwMTI3ODUwMTpqEF7rB3uBcGykpv6T2TisfTMhfZAvz1BP2Kcz70d1Sg",
                            "value": [
                                {
                                    "fieldName": "steps",
                                    "integerValue": 2600
                                },
                                {
                                    "fieldName": "duration",
                                    "integerValue": 20
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

[h2]What should I do if I cannot receive any notification message in HTTP subscription mode?

Perform the following to troubleshoot if you cannot receive notification messages in HTTP subscription mode:

1. Check whether you have enabled the subscription capability for your app, and whether the callback address has normal network requests.

To do this, sign in to HUAWEI Developers as an enterprise developer and go to Console > Health Service Kit > Manage, and check whether you have selected Registering the Subscription Notification Capability. Enter a callback address and test the connectivity. If the connectivity test fails, check the network of the callback address.

2. Check whether the user has successfully created a subscription record in your app.

To do so, call the API for querying subscription records, and check whether the user has successfully created a subscription record in your app. If an error is reported, troubleshoot by referring to Result Codes.

3. Check whether the ID of the app that creates the user subscription record is the same as that of your app.

4. Check whether the account used by the user to authorize your app is the same as the account used by the user to sign in to the Huawei Health app.

5. After a subscription record is created, make sure that new data is generated in the Huawei Health app.

[h2]How do I obtain information such as UnionID (union_id), OpenID (open_id) and scope of a Huawei user?

If your app has obtained the access token and needs to parse it to obtain information such as union_id, open_id, expire_in, and scope, please refer to Parsing an Access Token.