Back

[SOLVED] createMemberships in functions

  • 0
  • Teams
  • Functions
S3ppo
26 Oct, 2023, 13:35

i am trying to use a createMembership in a function like this: await teams.createMembership(mobiles.documents[0].teamid, ['mobile']);

but it always shows me an error:

TypeScript
Error: Missing required parameter: "url"
    at Teams.createMembership (/usr/local/server/src/function/node_modules/node-appwrite/lib/services/teams.js:243:19)
    at Module.default (file:///usr/local/server/src/function/src/main.js:28:17)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async execute (/usr/local/server/src/server.js:141:22)
    at async /usr/local/server/src/server.js:158:13

the docu shows that only teamid and role are required: https://appwrite.io/docs/references/1.4.x/server-nodejs/teams#createMembership

edit: i also tried it this way: await teams.createMembership(mobiles.documents[0].teamid, ['mobile'], 'test@test.at', userId, '', 'localhost' ); but then i get this:

TypeScript
Error: Invalid `email` param: Value must be a valid email address
    at Client.call (/usr/local/server/src/function/node_modules/node-appwrite/lib/client.js:172:31)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Teams.createMembership (/usr/local/server/src/function/node_modules/node-appwrite/lib/services/teams.js:271:16)
    at async Module.default (file:///usr/local/server/src/function/src/main.js:28:5)
    at async execute (/usr/local/server/src/server.js:141:22)
    at async /usr/local/server/src/server.js:158:13
TL;DR
User was trying to use the `createMembership` function in a Node.js app using the `node-appwrite` SDK. They were getting errors related to missing or invalid parameters. They tried different combinations of parameters but couldn't get it to work. The solution provided by another user was to use the correct syntax for the `createMembership` function, which is `await teams.createMembership(teamid, roles, email);`. The `teamid` and `roles` parameters are required, and `email` is optional. The user also mentioned that the URL parameter is required on the client SDK but optional on the server SDK. They clarified
S3ppo
26 Oct, 2023, 13:48

await teams.createMembership(mobiles.documents[0].teamid, ['mobile'], userId, null, null, 'localhost' ); i also tried this now and get this:

TypeScript
Error: Invalid `phone` param: Phone number must start with a '+' can have a maximum of fifteen digits.
    at Client.call (/usr/local/server/src/function/node_modules/node-appwrite/lib/client.js:172:31)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Teams.createMembership (/usr/local/server/src/function/node_modules/node-appwrite/lib/services/teams.js:271:16)
    at async Module.default (file:///usr/local/server/src/function/src/main.js:28:5)
    at async execute (/usr/local/server/src/server.js:141:22)
    at async /usr/local/server/src/server.js:158:13
Christy Jacob
26 Oct, 2023, 14:21

Are you using the client SDK or server SDK?

On the server SDK, URL is optional, but its required on the client SDK

Christy Jacob
26 Oct, 2023, 14:26

The snippet you shared is the correct usage

TypeScript
await teams.createMembership(teamid, roles, email);

This should work in theory.

S3ppo
26 Oct, 2023, 15:30

hey @Christy Jacob 🙂 thanks for your answer i started with the starter-template 😉

TypeScript
import { Client, Databases, Users, Teams, Query, ID } from 'node-appwrite';

export default async ({ req, res, log, error }) => {

  const client = new Client()
    .setEndpoint(process.env.ENDPOINT)
    .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
    .setKey(process.env.API_KEY);
S3ppo
26 Oct, 2023, 16:04
TypeScript
[Error] Message: {closure}(): Argument #3 ($userId) must be of type string, null given, called in /usr/src/code/vendor/utopia-php/framework/src/App.php on line 508
[Error] File: /usr/src/code/app/controllers/api/teams.php
[Error] Line: 391
[Error] Timestamp: 2023-10-26T16:01:18+00:00
[Error] Method: POST
[Error] URL: /v1/teams/:teamId/memberships
[Error] Type: Utopia\Exception
[Error] Message: Invalid `phone` param: Phone number must start with a '+' can have a maximum of fifteen digits.
[Error] File: /usr/src/code/vendor/utopia-php/framework/src/App.php
[Error] Line: 742
[Error] Timestamp: 2023-10-26T16:02:29+00:00
[Error] Method: POST
[Error] URL: /v1/teams/:teamId/memberships
[Error] Type: Appwrite\Extend\Exception
[Error] Message: Given email and phone doesn't match
[Error] File: /usr/src/code/app/controllers/api/teams.php
[Error] Line: 435
S3ppo
26 Oct, 2023, 16:05

this is all very strange, it shows me to fill the phone, then its wrong when i leave it empty, but on my users it is empty

S3ppo
26 Oct, 2023, 16:06

null seems to be wrong

S3ppo
26 Oct, 2023, 16:06

i dont understand it whats going on 😅

S3ppo
26 Oct, 2023, 16:13
TypeScript
[Error] Timestamp: 2023-10-26T16:12:02+00:00
[Error] Method: POST
[Error] URL: /v1/teams/:teamId/memberships
[Error] Type: Utopia\Exception
[Error] Message: Invalid `email` param: Value must be a valid email address
[Error] File: /usr/src/code/vendor/utopia-php/framework/src/App.php
[Error] Line: 742
Drake
26 Oct, 2023, 16:28

what version of the sdk do you have?

S3ppo
26 Oct, 2023, 16:31

Node-appwrite 11.0.0

Drake
26 Oct, 2023, 16:33

so you're passing userId for email

S3ppo
26 Oct, 2023, 16:33

No i passed nothing and tried to add the userid of my existing user 😉

S3ppo
26 Oct, 2023, 16:34

But meanwhile a tried a lot of combinations and i am very confused already 😜

S3ppo
26 Oct, 2023, 16:51

@Steven in my opinion this should work, but it leeds to await teams.createMembership(mobiles.documents[0].teamid, ['mobile'], null, userId, null, 'http://localhost' );

TypeScript
[Error] Timestamp: 2023-10-26T16:14:17+00:00
[Error] Method: POST
[Error] URL: /v1/teams/:teamId/memberships
[Error] Type: Utopia\Exception
[Error] Message: Invalid `email` param: Value must be a valid email address
[Error] File: /usr/src/code/vendor/utopia-php/framework/src/App.php
[Error] Line: 742
Drake
26 Oct, 2023, 16:56

can you try passing undefined instead of null?

S3ppo
26 Oct, 2023, 17:07

lol thanks that worked.. debugging for hours for that 😂

Drake
26 Oct, 2023, 17:39

[SOLVED] createMemberships in functions

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