createMembership method

Future<Membership> createMembership({
  1. required String teamId,
  2. required List<String> roles,
  3. String? email,
  4. String? userId,
  5. String? phone,
  6. String? url,
  7. String? name,
})

Create team membership

Invite a new member to join your team. Provide an ID for existing users, or invite unregistered users using an email or phone number. If initiated from a Client SDK, Appwrite will send an email or sms with a link to join the team to the invited user, and an account will be created for them if one doesn't exist. If initiated from a Server SDK, the new member will be added automatically to the team.

You only need to provide one of a user ID, email, or phone number. Appwrite will prioritize accepting the user ID > email > phone number if you provide more than one of these parameters.

Use the url parameter to redirect the user from the invitation email to your app. After the user is redirected, use the Update Team Membership Status endpoint to allow the user to accept the invitation to the team.

Please note that to avoid a Redirect Attack Appwrite will accept the only redirect URLs under the domains you have added as a platform on the Appwrite Console.

Implementation

Future<models.Membership> createMembership(
    {required String teamId,
    required List<String> roles,
    String? email,
    String? userId,
    String? phone,
    String? url,
    String? name}) async {
  final String apiPath =
      '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId);

  final Map<String, dynamic> apiParams = {
    'email': email,
    'userId': userId,
    'phone': phone,
    'roles': roles,
    'url': url,
    'name': name,
  };

  final Map<String, String> apiHeaders = {
    'content-type': 'application/json',
  };

  final res = await client.call(HttpMethod.post,
      path: apiPath, params: apiParams, headers: apiHeaders);

  return models.Membership.fromMap(res.data);
}