createMembership method

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

Create Team Membership

Invite a new member to join your team. If initiated from the client SDK, an email with a link to join the team will be sent to the member's email address and an account will be created for them should they not be signed up already. If initiated from server-side SDKs, the new member will automatically be added to the team.

Use the 'url' parameter to redirect the user from the invitation email back to your app. When 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 the only valid redirect URL's are the once from domains you have set when adding your platforms in the console interface.

Implementation

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

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

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

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

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