[SOLVED] The function `users.updateLabels` is returning an empty error.
- 0
- Self Hosted
- Functions
- Users
Maybe it’s because of the beta (using Starter Cloud), but this simple function is getting an empty error and isn’t updating the label.
import { Client, Users } from 'node-appwrite';
export default async ({ req, res, log, error }) => {
const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(process.env.APPWRITE_API_KEY);
const str = req.queryString;
const user_id = str.split('=')[1];
if (!user_id) {
error('User ID not provided');
return res.send('User ID is required', 400); // Bad Request
} else {
log(user_id);
}
const users = new Users(client);
// Update the user's labels
try {
const response = await users.updateLabels(user_id, ['subscriber']);
log(response);
return res.send('User labels updated successfully');
} catch (err) {
error(err);
return res.send('Failed to update user labels', 500); // Internal Server Error
}
};
version of node-appwrite?
also how are you sending the userId? as a json content, plain text?
Well, I use cloud version of the Appwrite that you got on the Starter tier. Functions are running in Node-18.0 Runtime. I've just clone starter function template, here's package.json:
{
"name": "starter-template",
"version": "1.0.0",
"description": "",
"main": "src/main.js",
"type": "module",
"scripts": {
"format": "prettier --write ."
},
"dependencies": {
"node-appwrite": "^9.0.0"
},
"devDependencies": {
"prettier": "^3.0.0"
}
}
userID is sending throw params from iOS client:
let execution = try await functions.createExecution(
functionId: "6527d2ed7f74ea014de7",
path: "/v1/params?userID=\(userID)",
method: "GET"
)
I've checked this id in the log and it is okay, issue with calling user API.
Oh, I see... current version of the node-appwrite is 11.0 already
Updated dependencies and the function completed successfully. It seems the templates need a small tune-up. Thanks @darShan !
[SOLVED]
[SOLVED] The function users.updateLabels is returning an empty error.
btw, you're seeing {} because you're doing error(err). You should make sure to pass a string there
Oh, right! Silly oversight from a Swift sailor in JavaScript seas ) Switch to log(err.message);
Btw, with node-appwrite": "^9.0.0" it returns users.updateLabels is not a function Start working properly from 10.0.0
afaik, 9.0.0 was built against 1.3x which didn't have the labels support. Labels were added in 1.4x.
Recommended threads
- AppwriteException: Invalid query: Query ...
```js console.log(typeof interaction.user.id) console.log(interaction.user.id) const user_check = await TablesDB.listRows({ databaseId: "db", ...
- AppwriteException - Transaction with the...
I am using "node-appwrite" module and I have successfully created transaction id but when passing it to tablesDB.createRow function with some other required dat...
- Files access permissions
Am I right in understanding that file access permissions have been disabled (or broken again), and that shared access can now only be organized via tokens? Or i...