0

I am getting an Invalid roles response when creating a team on appwrite with the node-appwrite package. Below is the code I'm using

import Sdk, { Permission, Role } from 'node-appwrite'

const client = new Sdk.Client()

client
    .setEndpoint(process.env.SERVER_URI)
    .setProject(process.env.PROJECT_ID)
    .setKey(process.env.SERVER_API_KEY)

const teams = new Sdk.Teams(client)

await teams.create('comics', 'Comics and Superheroes', [
    Permission.read(Role.users()),
    Permission.update(Role.team('admin')),
    Permission.delete(Role.team('admin'))
])

Below is the error response from the Request.

{
  code: 400,
  type: 'general_argument_invalid',
  response: {
    message: "Invalid roles: Value must a valid array and Parameter must contain at most 36 chars. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char",
    code: 400,
    type: 'general_argument_invalid',
    version: '1.2.0'
  }
}

if I log only the permissions being passed to the server, This is the result

[ 'read("users")', 'update("team:admin")', 'delete("team:admin")' ]

I believe the problem comes from the presence of semicolons and brackets in the strings. How can I resolve that, or am I missing something?

Penny Codes
  • 182
  • 2
  • 10

1 Answers1

1

The roles parameter of teams.create() accepts an array of strings that should be the available roles in the team. In your case, you need 2 roles: 1 for admin (which should be owner) and another for a regular member. As such, the call should probably be:

await teams.create('comics', 'Comics and Superheroes', [
    'member',
    'owner'
])

The Permission.read(Role.team('comics')), Permission.update(Role.team('comics', 'owner')), and Permission.delete(Role.team('comics', 'owner')) permissions can be used later when you're setting the permissions for a collection, document, bucket, or file.

Steven Nguyen
  • 452
  • 4
  • 4