Back

Issues with creating a new collection with appwrite-node-sdk

  • 0
  • Databases
  • Web
  • Users
  • Cloud
vishwa
11 Jan, 2024, 10:02

try { const response = await databases.createCollection('6583e3cd3184170786fb', '2ndStore', '2ndStore', ['role:all'],
['role:all'],

TypeScript
     attributes);
    console.log(response);
    res.status(200).json(response);
} catch (error) {
    console.error(error);
    res.status(500).json({ message: 'Error creating collection', error });
}

Gives: AppwriteException [Error]: Invalid permissions param: Invalid permission string format: "read".

How do i set roles?

TL;DR
Developers are experiencing issues with creating a new collection using the appwrite-node-sdk. They are trying to create the collection from the server-side, but it seems that it can only be done through a function instead of client-side. They also need help setting permissions to all while creating the collection. A potential solution is to use the `Role.any()` function instead of `Role.all` when setting permissions. Additionally, the permission string format should be adjusted to ["role:all"] instead of just "read".
D5
11 Jan, 2024, 10:16

Role.all doesn't exists. I think you mean Role.any()

vishwa
11 Jan, 2024, 10:19

Doesnt work

vishwa
11 Jan, 2024, 10:20

Could you please tell me how to set permissions to all while creating a collection

D5
11 Jan, 2024, 10:20

It's not specified in docs, but I think you need to do that through a function instead of client side

vishwa
11 Jan, 2024, 10:21

Oh

vishwa
11 Jan, 2024, 10:21

So it couldnt be done via node sdk?

D5
11 Jan, 2024, 10:21

Also to create collections it will be needed to do that server side instead of client side

vishwa
11 Jan, 2024, 10:21

Yeh i am trying to get it done from the server side only

vishwa
11 Jan, 2024, 10:22

export async function POST(req, res) {

TypeScript
const url = new URL(req.url, `http://${req.headers.host}`);

const sdk = require('node-appwrite');

const client = new sdk.Client();

const databases = new sdk.Databases(client); const attributes = [ { "type": "string", "key": "Data", "label": "Data", "required": false, "array": false },

]; client .setEndpoint('https://cloud.appwrite.io/v1') .setProject('') .setKey('') ;

TypeScript
try {
    const response = await databases.createCollection('6583e3cd3184170786fb', '2ndStore', '2ndStore', 

['Role.any()'],
attributes); console.log(response); res.status(200).json(response); } catch (error) { console.error(error); res.status(500).json({ message: 'Error creating collection', error }); } } here is what i am trying to do

vishwa
11 Jan, 2024, 10:42

@D5 sir?

D5
11 Jan, 2024, 10:52

Is this an appwrite function?

D5
11 Jan, 2024, 10:53

If you run this in an AW function there should not be any issues

vishwa
11 Jan, 2024, 10:59

Nope its not an AW function

vishwa
11 Jan, 2024, 10:59

[ Permission.read(sdk.Role.any()),

TypeScript
    ],
vishwa
11 Jan, 2024, 10:59

using this worked

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