[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
- Having issues with login via CLI
``` ~/appwrite appwrite login --endpoint https://localhost/v1 --verbose ? Enter your email myvalidemai...
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Send Email Verification With REST
I am using REST to create a user on the server side after receiving form data from the client. After the account is successfully created i wanted to send the v...