batchUpdateTeamMember method

Future<Map<String, TeamMember>> batchUpdateTeamMember({
  1. required TeamMemberBatchUpsertRequest request,
  2. String? authToken,
})

Updates multiple TeamMember objects.

The updated TeamMember objects are returned on successful updates. This process is non-transactional and processes as much of the request as possible. If one of the updates in the request cannot be successfully processed, the request is not marked as failed, but the body of the response contains explicit error information for the failed update. Learn about Troubleshooting the Team API.

Implementation

Future<Map<String, TeamMember>> batchUpdateTeamMember({
  required TeamMemberBatchUpsertRequest request,
  String? authToken,
}) async {

  authToken ??= authenticationService.getCachedToken()?.accessToken;

  Map<String, String> headers = {
    "Authorization": "Bearer ${authToken ?? ""}",
    'Content-Type': 'application/json; charset=UTF-8',
    'Accept': 'application/json',

  };

  Uri endpoint = Uri.https(
      baseUrl, "/v2/team-members/bulk-update");

  //print (endpoint.toString());

  var response = await
  http.post(endpoint, body: jsonEncode(request.toJson()), headers: headers);

  if (response.statusCode == 200) {
    print (jsonDecode(response.body));
    return TeamMemberBatchResponse.fromJson(jsonDecode(response.body)).teamMembers!.map((key, value) => MapEntry(key, value.teamMember!));
  }
  else {
    print (response.body);
    throw TeamMemberException(statusCode: response.statusCode, message: TeamMemberBatchResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
  }
}