discontinuedPackage thingsboard_pe_client has been discontinued and replaced by thingsboard_client.

getAttributesByScope method

Future<Response<BuiltList<AttributeData>>> getAttributesByScope({
  1. required String entityType,
  2. required String entityId,
  3. required String scope,
  4. String? keys,
  5. BuiltList<String>? key,
  6. CancelToken? cancelToken,
  7. Map<String, dynamic>? headers,
  8. Map<String, dynamic>? extra,
  9. ValidateStatus? validateStatus,
  10. ProgressCallback? onSendProgress,
  11. ProgressCallback? onReceiveProgress,
})

Get attributes by scope (getAttributesByScope) Returns all attributes of a specified scope that belong to specified entity. List of possible attribute scopes depends on the entity type: * SERVER_SCOPE - supported for all entity types; * SHARED_SCOPE - supported for devices; * CLIENT_SCOPE - supported for devices. Use optional 'keys' parameter to return specific attributes. Example of the result: ```json [ {&quot;key&quot;: &quot;stringAttributeKey&quot;, &quot;value&quot;: &quot;value&quot;, &quot;lastUpdateTs&quot;: 1609459200000}, {&quot;key&quot;: &quot;booleanAttributeKey&quot;, &quot;value&quot;: false, &quot;lastUpdateTs&quot;: 1609459200001}, {&quot;key&quot;: &quot;doubleAttributeKey&quot;, &quot;value&quot;: 42.2, &quot;lastUpdateTs&quot;: 1609459200002}, {&quot;key&quot;: &quot;longKeyExample&quot;, &quot;value&quot;: 73, &quot;lastUpdateTs&quot;: 1609459200003}, {&quot;key&quot;: &quot;jsonKeyExample&quot;, &quot;value&quot;: { &quot;someNumber&quot;: 42, &quot;someArray&quot;: 1,2,3, &quot;someNestedObject&quot;: {&quot;key&quot;: &quot;value&quot;} }, &quot;lastUpdateTs&quot;: 1609459200004 } ] ``` Referencing a non-existing entity Id or invalid entity type will cause an error. Available for users with 'TENANT_ADMIN' or 'CUSTOMER_USER' authority.

Parameters:

  • entityType - A string value representing the entity type. For example, 'DEVICE'
  • entityId - A string value representing the entity id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'
  • scope - A string value representing the attributes scope. For example, 'SERVER_SCOPE'.
  • keys - A string value representing the comma-separated list of attributes keys. For example, 'active,inactivityAlarmTime'. If attribute keys contain comma, duplicate 'key' parameter for each key, for example '?key=my,key&key=my,second,key
  • key - Repeatable key query parameter (alternative to comma-separated 'keys')
  • cancelToken - A CancelToken that can be used to cancel the operation
  • headers - Can be used to add additional headers to the request
  • extras - Can be used to add flags to the request
  • validateStatus - A ValidateStatus callback that can be used to determine request success based on the HTTP status of the response
  • onSendProgress - A ProgressCallback that can be used to get the send progress
  • onReceiveProgress - A ProgressCallback that can be used to get the receive progress

Returns a Future containing a Response with a BuiltList<AttributeData> as data Throws DioException if API call or serialization fails

Implementation

Future<Response<BuiltList<AttributeData>>> getAttributesByScope({
  required String entityType,
  required String entityId,
  required String scope,
  String? keys,
  BuiltList<String>? key,
  CancelToken? cancelToken,
  Map<String, dynamic>? headers,
  Map<String, dynamic>? extra,
  ValidateStatus? validateStatus,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
}) async {
  final _serializers =
      this._serializers ??
      apiSerializers(registerListOfAttributeDataAndListOfString);
  final _path =
      r'/api/plugins/telemetry/{entityType}/{entityId}/values/attributes/{scope}'
          .replaceAll(
            '{'
            r'entityType'
            '}',
            encodeQueryParameter(
              _serializers,
              entityType,
              const FullType(String),
            ).toString(),
          )
          .replaceAll(
            '{'
            r'entityId'
            '}',
            encodeQueryParameter(
              _serializers,
              entityId,
              const FullType(String),
            ).toString(),
          )
          .replaceAll(
            '{'
            r'scope'
            '}',
            encodeQueryParameter(
              _serializers,
              scope,
              const FullType(String),
            ).toString(),
          );
  final _options = Options(
    method: r'GET',
    headers: <String, dynamic>{...?headers},
    extra: <String, dynamic>{
      'secure': <Map<String, String>>[
        {
          'type': 'apiKey',
          'name': 'ApiKeyForm',
          'keyName': 'X-Authorization',
          'where': 'header',
        },
        {'type': 'http', 'scheme': 'loginPassword', 'name': 'HttpLoginForm'},
      ],
      ...?extra,
    },
    validateStatus: validateStatus,
  );

  final _queryParameters = <String, dynamic>{
    if (keys != null)
      r'keys': encodeQueryParameter(
        _serializers,
        keys,
        const FullType(String),
      ),
    if (key != null)
      r'key': encodeCollectionQueryParameter<String>(
        _serializers,
        key,
        const FullType(BuiltList, [FullType(String)]),
        format: ListFormat.multi,
      ),
  };

  final _response = await _dio.request<Object>(
    _path,
    options: _options,
    queryParameters: _queryParameters,
    cancelToken: cancelToken,
    onSendProgress: onSendProgress,
    onReceiveProgress: onReceiveProgress,
  );

  BuiltList<AttributeData>? _responseData;

  try {
    final rawResponse = _response.data;
    _responseData = rawResponse == null
        ? null
        : _serializers.deserialize(
                rawResponse,
                specifiedType: const FullType(BuiltList, [
                  FullType(AttributeData),
                ]),
              )
              as BuiltList<AttributeData>;
  } catch (error, stackTrace) {
    throw DioException(
      requestOptions: _response.requestOptions,
      response: _response,
      type: DioExceptionType.unknown,
      error: error,
      stackTrace: stackTrace,
    );
  }

  return Response<BuiltList<AttributeData>>(
    data: _responseData,
    headers: _response.headers,
    isRedirect: _response.isRedirect,
    requestOptions: _response.requestOptions,
    redirects: _response.redirects,
    statusCode: _response.statusCode,
    statusMessage: _response.statusMessage,
    extra: _response.extra,
  );
}