getAttributesByScope method
- 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,
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 [ {"key": "stringAttributeKey", "value": "value", "lastUpdateTs": 1609459200000}, {"key": "booleanAttributeKey", "value": false, "lastUpdateTs": 1609459200001}, {"key": "doubleAttributeKey", "value": 42.2, "lastUpdateTs": 1609459200002}, {"key": "longKeyExample", "value": 73, "lastUpdateTs": 1609459200003}, {"key": "jsonKeyExample", "value": { "someNumber": 42, "someArray": 1,2,3, "someNestedObject": {"key": "value"} }, "lastUpdateTs": 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,keykey- Repeatable key query parameter (alternative to comma-separated 'keys')cancelToken- ACancelTokenthat can be used to cancel the operationheaders- Can be used to add additional headers to the requestextras- Can be used to add flags to the requestvalidateStatus- AValidateStatuscallback that can be used to determine request success based on the HTTP status of the responseonSendProgress- AProgressCallbackthat can be used to get the send progressonReceiveProgress- AProgressCallbackthat 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,
);
}