searchEntities method

Future<SearchEntitiesResponse> searchEntities({
  1. required List<EntityType> entityTypes,
  2. List<EntityFilter>? filters,
  3. int? maxResults,
  4. int? namespaceVersion,
  5. String? nextToken,
})

Searches for entities of the specified type. You can search for entities in your namespace and the public namespace that you're tracking.

May throw InvalidRequestException. May throw InternalFailureException. May throw ThrottlingException.

Parameter entityTypes : The entity types for which to search.

Parameter filters : Optional filter to apply to the search. Valid filters are NAME NAMESPACE, SEMANTIC_TYPE_PATH and REFERENCED_ENTITY_ID. REFERENCED_ENTITY_ID filters on entities that are used by the entity in the result set. For example, you can filter on the ID of a property that is used in a state.

Multiple filters function as OR criteria in the query. Multiple values passed inside the filter function as AND criteria.

Parameter maxResults : The maximum number of results to return in the response.

Parameter namespaceVersion : The version of the user's namespace. Defaults to the latest version of the user's namespace.

Parameter nextToken : The string that specifies the next page of results. Use this when you're paginating results.

Implementation

Future<SearchEntitiesResponse> searchEntities({
  required List<EntityType> entityTypes,
  List<EntityFilter>? filters,
  int? maxResults,
  int? namespaceVersion,
  String? nextToken,
}) async {
  ArgumentError.checkNotNull(entityTypes, 'entityTypes');
  _s.validateNumRange(
    'maxResults',
    maxResults,
    1,
    250,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'IotThingsGraphFrontEndService.SearchEntities'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'entityTypes': entityTypes.map((e) => e.toValue()).toList(),
      if (filters != null) 'filters': filters,
      if (maxResults != null) 'maxResults': maxResults,
      if (namespaceVersion != null) 'namespaceVersion': namespaceVersion,
      if (nextToken != null) 'nextToken': nextToken,
    },
  );

  return SearchEntitiesResponse.fromJson(jsonResponse.body);
}