defineFilter method
Uploads a new filter definition to the node. Returns a filter ID that may be used in future requests to restrict which events are returned to the client.
userId
The id of the user uploading the filter. The access token must be authorized to make requests for this user id.
filter
The filter to upload.
returns filter_id
:
The ID of the filter that was created. Cannot start
with a {
as this character is used to determine
if the filter provided is inline JSON or a previously
declared filter by nodes on some APIs.
Implementation
Future<String> defineFilter(String userId, Filter filter) async {
final requestUri =
Uri(path: '_api/client/v3/user/${Uri.encodeComponent(userId)}/filter');
final request = Request('POST', baseUri!.resolveUri(requestUri));
request.headers['authorization'] = 'Bearer ${bearerToken!}';
request.headers['content-type'] = 'application/json';
request.bodyBytes = utf8.encode(jsonEncode(filter.toJson()));
final response = await httpClient.send(request);
final responseBody = await response.stream.toBytes();
if (response.statusCode != 200) unexpectedResponse(response, responseBody);
final responseString = utf8.decode(responseBody);
final json = jsonDecode(responseString);
return json['filter_id'] as String;
}