Get Asset Latest Data

Get the latest data of the specified measurement points of specified devices.

Operation Permissions

Required Authorization

Required Operation Permission

Asset

Read

For more information about resources and required permission, see Policies, Roles and Permissions>>

Request Format

POST https://{apigw-address}/tsdb-service/v2.1/latest

Request Parameters (URI)

Name

Location (Path/Query)

Mandatory/Optional

Data Type

Description

orgId

Query

Mandatory

String

The organization ID which the asset belongs to. How to get organization ID>>

Request Parameters (Body)

Name

Mandatory/Optional

Data Type

Description

modelId

Optional

String

The model ID.`How to get model ID>> </docs/api/en/2.1.0/api_faqs#how-to-get-model-id-modelid-modelid>`__

assetIds

Mandatory

String

The asset ID. Supports the query of multiple asset IDs, separated by commas. How to get asset ID>>

pointIds

Mandatory

String

The measurement point ID. Supports the query of multiple measurement point IDs, separated by commas. The upper limit of the number of measurement points that can be queried is 3,000 (number of devices * number of measurement points). How to get measurement point ID>>

timeWindow

Optional

Integer

Specify the time window for querying the latest data (by minutes). The minimum value is 0. If not specified, no constrain is applied.

ifWithLocalTime

Optional

Boolean

  • true = returns data in local time format

  • false (default) = does not return data in local time format

localTimeAccuracy

Optional

Boolean

  • true = query returns data with millisecond time stamp

  • false (default) = query returns data without millisecond time stamp

localTimeFormat

Optional

Integer

Specify whether the local time value includes time zone information of devices. 0 (default): without time zone information; 1: with time zone information.

itemFormat

Optional

Integer

Specify the displaying format of the returned device data. Available options are 0, 1, and 2. For the example of each displaying format, see Item Format Example>>

Response Parameters

Name

Data Type

Description

data

List<JSONObject>

The list of asset data. The data returned for a single point of a single device is sorted by the data time stamp in ascending order. For more information, see items

items

Sample

{
        "assetId": "4DXYH7nS",
        "opentsdb_pi_point": "1.1236",
        "timestamp": 1560249312446
}

Parameters

Name

Data Type

Description

assetId

String

The asset ID.

timestamp

Long

The data timestamp (UNIX time, accurate to the second).

pointId

Double

This parameter is a variable, representing the identifier and data of the measurement point.

localtime

String

The data timestamp in local time format (accurate to the second). The value of the localTimeFormat parameter determines whether the local time value includes the time zone information.

Error Codes

For description of error codes, see Common Error Codes.

Sample

Request Sample

url: https://{apigw-address}/tsdb-service/v2.1/latest?orgId=yourOrgId

method: POST

Content-Type: application/json

requestBody:
{
  "pointIds": "pi_point",
  "ifWithLocalTime": "true",
  "timeWindow": "",
  "assetIds": "Ps4PViva",
  "localTimeFormat": 1,
  "localTimeAccuracy": "false",
  "itemFormat": 0
}

Return Sample

{
  "code": 0,
  "msg": "OK",
  "submsg": null,
  "data": {
    "items": [
      {
        "localtime":"2020-03-31T23:59:59+08:00",
        "assetId": "Ps4PViva",
        "pi_point": 2.123,
        "timestamp": 1585670399000
      }
    ]
  }
}

Java SDK Sample

import com.alibaba.fastjson.JSONObject;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envision.apim.poseidon.request.PoseidonRequest;
import org.junit.Before;
import org.junit.Test;

public class Sample {
    private static final String API_Gateway_URL = "https://{domain_url}";
    private Poseidon poseidon;

    private static class Request extends PoseidonRequest {

        public void setBodyParams(String key, Object value) {
            bodyParams().put(key, value);
        }

        public void setMethod(String method) {
            this.method = method;
        }

        private String method;

        @Override
        public String baseUri() {
            return "";
        }

        @Override
        public String method() {
            return method;
        }
    }

    @Before
    public void init() {
        poseidon = Poseidon.config(
                PConfig.init()
                        .appKey("AccessKey of your APP")
                        .appSecret("SecretKey of your APP")
        ).method("POST").header("Content-Type", "application/json");
    }

    @Test
    public void GetAssetLatestData() {
        Request request = new Request();
        request.setBodyParams("assetIds", "yourAssetId1,yourAssetId2");
        request.setBodyParams("pointIds", "yourPointId");
        request.setBodyParams("ifWithLocalTime", true);
        request.setBodyParams("localTimeAccuracy", false);
        request.setBodyParams("localTimeFormat", 1);
        request.setBodyParams("itemFormat", 0);

        JSONObject response =  poseidon
                .url(API_Gateway_URL + "/tsdb-service/v2.1/latest")
                .queryParam("orgId", "yourOrgId")
                .getResponse(request, JSONObject.class);
        System.out.println(response);
    }
}