Back

Add User to a team

  • 0
  • Web
arswizz
4 Oct, 2023, 08:44

I'm using Angular on Ionic app, i'm able to create a team but i have a problem when i try to add new user to that team ; ``}

TypeScript
    addUsertoTheTeam(){
      const client = this.client.setEndpoint('https://cloud.appwrite.io/v1')
      .setProject('****************'); 
     const teams = new Teams(client);
      teams.createMembership('***************',[
        'email','**********************@gmail.com',
        'roles', Role.member('**********************'),
          
            Permission.read(Role.team("*****************")),   
            Permission.update(Role.team("***************", "owner")), 
            Permission.delete(Role.team("******************", "owner"))  
          
      ]).then(response=> {
        console.log('member created : ', response);

       }, function (error) {
        console.log('error on created team', error);
      });
    }``
TL;DR
User is trying to add a new user to a team using the Discord API. They have tried different methods but haven't been successful. They need help with an example of how to add a user to a team without sending an email. The user provides code snippets and asks for assistance with the correct syntax. Another user suggests that the documentation may be incorrect and provides a modified syntax for adding a user to a team. The original user asks for clarification on the issue and provides code they are using with Angular on an Ionic app. Solution: Based on the discussion, it appears that the correct syntax for adding a user to a team is as
safwan
4 Oct, 2023, 08:47

What's the problem here?

darShan
4 Oct, 2023, 08:49

roles is an array, I don't think it will take email.

safwan
4 Oct, 2023, 08:50

I think the docs are missing something. Give me a minute

safwan
4 Oct, 2023, 08:53

Can you try this?

TypeScript
const promise = await teams.createMembership(
  '[TEAM_ID]', 
  'email@example.com', 
  [
    // add roles here
  ]
);
darShan
4 Oct, 2023, 08:53

Should be something like this:

TypeScript
await teams.createMembership('teamId', [
  sdk.Role.user('userIdOne'),
  sdk.Role.user('userIdTwo'),
  sdk.Role.user('userIdThree'),
], 'xyz@gmail.com');
darShan
4 Oct, 2023, 08:54

This is what I can understand from the source.

safwan
4 Oct, 2023, 08:55

I haven't used the createMembership endpoint in 1.4, so not sure what the correct syntax is.

The request params specify, in the same order:

  • email
  • userId
  • phone
  • roles (required)
  • url
  • name

So I assumed the email comes before the roles

darShan
4 Oct, 2023, 08:55

Signature is changed

darShan
4 Oct, 2023, 08:56
TypeScript
async createMembership(teamId, roles, email, userId, phone, url, name) {}
darShan
4 Oct, 2023, 08:57

OP has added the email & roles inside the array. Also, I'm not sure how permissions come into play here.

darShan
4 Oct, 2023, 08:58

Doc. doesn't seem to be correct.

darShan
4 Oct, 2023, 08:59

A issue would be good for this I think.

darShan
5 Oct, 2023, 05:37

The docs. seem to be fixed now.

arswizz
5 Oct, 2023, 12:19

can you help me with some eg

Drake
5 Oct, 2023, 16:29

FYI, it's best to use 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.

arswizz
6 Oct, 2023, 06:07

i mean server side please

Drake
6 Oct, 2023, 14:23

It's the same API/method

arswizz
6 Oct, 2023, 14:24

I saw a method to add user to the team without sending email

arswizz
6 Oct, 2023, 14:24

I tried many method till doday, i'm not able

D5
6 Oct, 2023, 15:12

Client sided is exactly the same way steven suggested. Make sure you have the API key stablished with the corresponding scopes

D5
6 Oct, 2023, 15:12

Yes, that one is exclusive for server side use

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more