目录

Creating/Updating an Activity Record

Function

Creates or updates an activity record, and writes Exercise and Move data into Activity Rings.

Scenario

Creates or updates an activity record, such as for running or rope jumping.

Restrictions

You can call this API to write the statistical data for data types described in the following table.

Statistical Data Type

Statistical Type Name

Atomic Data Type

Steps

com.huawei.continuous.steps.total

com.huawei.continuous.steps.delta

Distance

com.huawei.continuous.distance.total

com.huawei.continuous.distance.delta

Calories

com.huawei.continuous.calories.burnt.total

com.huawei.continuous.calories.burnt

Exercise heart rate

com.huawei.continuous.exercise_heart_rate.statistics

com.huawei.instantaneous.exercise_heart_rate

Step cadence

com.huawei.continuous.steps.rate.statistics

com.huawei.instantaneous.steps.rate

Jump

com.huawei.continuous.jump.statistics

com.huawei.continuous.jump

Speed

com.huawei.continuous.speed.statistics

com.huawei.continuous.speed

Resting calories

com.huawei.resting_calories.statistics

-

API Prototype

Protocol

HTTPS PUT

Direction

App > Health Service Kit cloud

URL

https://health-api.cloud.huawei.com/healthkit/v2/activityRecords/{activityRecordId}

Data Format

Request: Content-Type: application/json

Response: Content-Type: application/json

Route Parameters

Parameter

Type

Mandatory

Description

activityRecordId

String

Yes

ID of the activity record. The value must be the same as the request body ID and contains 1 to 1000 characters.

Request Parameters

Request header

Parameter

Type

Mandatory

Description

Content-type

String

Yes

Value: application/json; charset=UTF-8

Authorization

String

Yes

For details, see Authentication.

NOTE:

A space character must be added between Bearer and the value of access_token.

x-client-id

String

No

App ID allocated by HUAWEI Developers. The server can perform gray routing based on this parameter. It is recommended that this parameter be carried.

x-version

String

No

Software version number of the app calling the API, that is, the version number of the current client. The server can perform gray release based on this parameter. It is recommended that this parameter be carried.

x-caller-trace-id

String

No

Request tracing ID, which is used to connect the entire request chain between the service calling party and server. It is recommended that this parameter be carried.

Request body

Parameter

Type

Mandatory

Description

appInfo

AppInfo

Yes

App information of the data collector. For details, please refer to AppInfo data model.

id

String

No

ID generated by the client for an activity record. It is unique across all activity records owned by the user.

The value must be the same as that of activityRecordId as the route parameter and contains 1 to 1000 characters.

startTime

Long

Yes

Start time of the activity record (in milliseconds).

The value must be a 13-digit integer timestamp, ranging from 2000-01-01 00:00:00 to 2099-12-31 23:59:59.

startTime must be earlier than endTime.

The duration specified by startTime and endTime must not exceed 5 days.

endTime

Long

Yes

End time of the activity record (in milliseconds).

The value must be a 13-digit integer timestamp, ranging from 2000-01-01 00:00:00 to 2099-12-31 23:59:59.

endTime must be later than startTime.

The duration specified by startTime and endTime must not exceed 5 days.

timeZone

String

Yes

Time zone information. Example: +0800

activityType

Integer

Yes

Activity type constant corresponding to the activity record. For example, running corresponds to 56.

deviceInfo

DeviceInfo

No

Description of the hardware device that integrates various sensors, such as a watch, a band, or any other wearable devices.

For details, please refer to DeviceInfo data model.

activeTime

Long

No

Active time of the activity record (in milliseconds). It can be written into Activity Rings.

activitySummary

ActivitySummary

Yes

Summary of the activity record. For details, please refer to ActivitySummary data model.

desc

String

No

Description of the activity record. Length range: 1 to 1000 characters

subDataRelation

List<SamplePointRelation>

No

Subdata mapping.

details

List<SampleSet>

No

Activity record details. For details, please refer to SampleSet data model.

modifyTime

Long

No

The last time the activity record was modified.

If modifyTime is specified when creating activityRecords, the passed modifyTime value will be returned when the UI returns the activityRecords information created by the user.

name

String

No

User-defined name of the activity record. Length range: 1 to 1000 characters

Request Example

PUT
https://health-api.cloud.huawei.com/healthkit/v2/activityRecords/sportHealth1775787812164
Content-Type: application/json
Authorization: Bearer ***
x-client-id: ***
x-version: ***
x-caller-trace-id: **
{
    "activityType": 56,
    "appInfo": {
        "appName": "app9",
        "appVersion": "1",
        "desc": "1"
    },
    "endTime": 1775786400000,
    "name": "sportHealth1775787812164",
    "id": "sportHealth1775787812164",
    "desc": "sportHealth1775787812164",
    "modifyTime": 1775786400000,
    "startTime": 1775784600000,
    "activeTime": 610000,
    "activitySummary": {
        "paceSummary": {
            "paceMap": {
                "1.0": 478.0,
                "1.21": 628.0
            },
            "sportHealthPaceMap": {
                "5600000": 746.0
            },
            "partTimeMap": {
                "1.0": 478.0
            },
            "avgPace": 746.42857,
            "bestPace": 0.0
        },
        "performanceSummary": {
            "aerobicTrainingStress": 1.2,
            "anaerobicTrainingStress": 1.3,
            "recoveryTime": 10,
            "vo2Max": 35
        },
        "dataSummary": [
            {
                "startTime": 1724997600000000000,
                "endTime": 1724999490000000000,
                "dataTypeName": "com.huawei.continuous.calories.burnt.total",
                "value": [
                    {
                        "fieldName": "calories_total",
                        "floatValue": 31.0
                    }
                ]
            },
            {
                "startTime": 1724997600000000000,
                "endTime": 1724999490000000000,
                "dataTypeName": "com.huawei.continuous.steps.total",
                "value": [
                    {
                        "fieldName": "steps",
                        "integerValue": 701
                    },
                    {
                        "fieldName": "duration",
                        "integerValue": 6
                    }
                ]
            },
            {
                "startTime": 1724997600000000000,
                "endTime": 1724999490000000000,
                "dataTypeName": "com.huawei.continuous.distance.total",
                "value": [
                    {
                        "fieldName": "distance",
                        "floatValue": 560.0
                    }
                ]
            },
            {
                "startTime": 1724997600000000000,
                "endTime": 1724999490000000000,
                "dataTypeName": "com.huawei.continuous.exercise_heart_rate.statistics",
                "value": [
                    {
                        "fieldName": "avg",
                        "floatValue": 100.0
                    },
                    {
                        "fieldName": "max",
                        "floatValue": 111.0
                    },
                    {
                        "fieldName": "min",
                        "floatValue": 78.0
                    }
                ]
            },
            {
                "startTime": 1724997600000000000,
                "endTime": 1724999490000000000,
                "dataTypeName": "com.huawei.continuous.steps.rate.statistics",
                "value": [
                    {
                        "fieldName": "avg",
                        "floatValue": 100.0
                    },
                    {
                        "fieldName": "max",
                        "floatValue": 132.0
                    },
                    {
                        "fieldName": "min",
                        "floatValue": 0.0
                    }
                ]
            },
            {
                "startTime": 1724997600000000000,
                "endTime": 1724999490000000000,
                "dataTypeName": "com.huawei.continuous.speed.statistics",
                "value": [
                    {
                        "fieldName": "avg",
                        "floatValue": 1.34
                    },
                    {
                        "fieldName": "max",
                        "floatValue": 1.34
                    }
                ]
            }
        ]
    },
    "timeZone": "+0800"
}

Response Parameters

When the status code is 200:

Response header

Type

Type

Mandatory

Description

Content-Type

String

Yes

Value: application/json; charset=UTF-8

Response body

Parameter

Type

Mandatory

Description

id

String

Yes

ID generated by the client for an activity record. It is unique across all activity records owned by the user.

The value must be the same as that of activityRecordId as the route parameter and contains 1 to 1000 characters.

startTime

Long

Yes

Start time of an activity record. The unit is milliseconds.

The value must be a 13-digit integer timestamp, ranging from 2000-01-01 00:00:00 to 2099-12-31 23:59:59.

startTime must be earlier than endTime.

The duration specified by startTime and endTime must not exceed 5 days.

endTime

Long

Yes

End time of an activity record. The unit is milliseconds.

The value must be a 13-digit integer timestamp, ranging from 2000-01-01 00:00:00 to 2099-12-31 23:59:59.

endTime must be later than startTime.

The duration specified by startTime and endTime must not exceed 5 days.

timeZone

String

Yes

Time zone information. Example: +0800

appInfo

AppInfo

Yes

App information of the data collector. For details, please refer to AppInfo data model.

activityType

Integer

No

Activity type constant corresponding to the activity record. For example, running corresponds to 56.

activeTime

Long

No

Active time of the activity record, in milliseconds.

desc

String

No

Description of the activity record. Length range: 1 to 1000 characters

activitySummary

ActivitySummary

No

Summary of the activity record. For details, please refer to ActivitySummary data model.

details

List<SampleSet>

No

Activity record details. For details, please refer to SampleSet data model.

deviceInfo

DeviceInfo

No

Description of the hardware device that integrates various sensors, such as a watch, a band, or any other wearable devices.

For details, please refer to DeviceInfo data model.

subDataRelation

List<SamplePointRelation>

No

Subdata mapping.

modifyTime

Long

No

The last time the activity record was modified.

If modifyTime is specified when creating activityRecords, the passed modifyTime value will be returned when the UI returns the activityRecords information created by the user.

name

String

No

User-defined name of the activity record. Length range: 1 to 1000 characters

Response Example

HTTP/1.1 200 OK
Content-type: application/json;charset=utf-8
{
    "id": "sportHealth1775787812164",
    "name": "sportHealth1775787812164",
    "desc": "sportHealth1775787812164",
    "startTime": 1775784600000,
    "endTime": 1775786400000,
    "modifyTime": 1775786400000,
    "activitySummary": {
        "paceSummary": {
            "paceMap": {
                "1.0": 478.0,
                "1.21": 628.0
            },
            "sportHealthPaceMap": {
                "5600000": 746.0
            },
            "partTimeMap": {
                "1.0": 478.0
            },
            "avgPace": 746.42857,
            "bestPace": 0.0
        },
        "performanceSummary": {
            "aerobicTrainingStress": 1.2,
            "anaerobicTrainingStress": 1.3,
            "recoveryTime": 10,
            "vo2Max": 35
        },
        "dataSummary": [
            {
                "startTime": 1724997600000000000,
                "endTime": 1724999490000000000,
                "dataTypeName": "com.huawei.continuous.calories.burnt.total",
                "value": [
                    {
                        "fieldName": "calories_total",
                        "floatValue": 31.0
                    }
                ]
            },
            {
                "startTime": 1724997600000000000,
                "endTime": 1724999490000000000,
                "dataTypeName": "com.huawei.continuous.steps.total",
                "value": [
                    {
                        "fieldName": "duration",
                        "integerValue": 6
                    },
                    {
                        "fieldName": "steps",
                        "integerValue": 701
                    }
                ]
            },
            {
                "startTime": 1724997600000000000,
                "endTime": 1724999490000000000,
                "dataTypeName": "com.huawei.continuous.distance.total",
                "value": [
                    {
                        "fieldName": "distance",
                        "floatValue": 560.0
                    }
                ]
            },
            {
                "startTime": 1724997600000000000,
                "endTime": 1724999490000000000,
                "dataTypeName": "com.huawei.continuous.exercise_heart_rate.statistics",
                "value": [
                    {
                        "fieldName": "min",
                        "floatValue": 78.0
                    },
                    {
                        "fieldName": "avg",
                        "floatValue": 100.0
                    },
                    {
                        "fieldName": "max",
                        "floatValue": 111.0
                    }
                ]
            },
            {
                "startTime": 1724997600000000000,
                "endTime": 1724999490000000000,
                "dataTypeName": "com.huawei.continuous.steps.rate.statistics",
                "value": [
                    {
                        "fieldName": "min",
                        "floatValue": 0.0
                    },
                    {
                        "fieldName": "avg",
                        "floatValue": 100.0
                    },
                    {
                        "fieldName": "max",
                        "floatValue": 132.0
                    }
                ]
            },
            {
                "startTime": 1724997600000000000,
                "endTime": 1724999490000000000,
                "dataTypeName": "com.huawei.continuous.speed.statistics",
                "value": [
                    {
                        "fieldName": "avg",
                        "floatValue": 1.34
                    },
                    {
                        "fieldName": "max",
                        "floatValue": 1.34
                    }
                ]
            }
        ]
    },
    "timeZone": "+0800",
    "appInfo": {
        "appName": "app9",
        "appVersion": "1",
        "desc": "1",
        "clientId": "104446763"
    },
    "activityType": 56,
    "activeTime": 610000,
    "sourceType": 0,
    "abnormal": 0,
    "duplicate": 0
}

Result Codes

For details, see Result Codes.