Back

[SOLVED] The function `users.updateLabels` is returning an empty error.

  • 0
  • Self Hosted
  • Functions
  • Users
Alex
12 Oct, 2023, 11:52

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.

TL;DR
The user is experiencing an issue with the function `users.updateLabels` returning an empty error. The issue is due to using an outdated version of the `node-appwrite` library. Upgrading to version `10.0.0` or higher resolved the issue for the user. Additionally, the user provides a code snippet and mentions a possible issue with calling the user API. The user's code appears to be correctly sending the userID as a query parameter. It is recommended to check the API endpoint and make sure the user ID is being passed correctly.
Alex
12 Oct, 2023, 11:52
TypeScript
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
    }
};
darShan
12 Oct, 2023, 12:47

version of node-appwrite?

darShan
12 Oct, 2023, 12:48

also how are you sending the userId? as a json content, plain text?

Alex
12 Oct, 2023, 13:35

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:

TypeScript
{
  "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:

TypeScript
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.

Alex
12 Oct, 2023, 13:51

Oh, I see... current version of the node-appwrite is 11.0 already

Alex
12 Oct, 2023, 17:04

Updated dependencies and the function completed successfully. It seems the templates need a small tune-up. Thanks @darShan !

Alex
12 Oct, 2023, 17:05

[SOLVED]

Drake
12 Oct, 2023, 17:17

[SOLVED] The function users.updateLabels is returning an empty error.

Drake
12 Oct, 2023, 17:18

btw, you're seeing {} because you're doing error(err). You should make sure to pass a string there

Alex
13 Oct, 2023, 08:25

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

darShan
13 Oct, 2023, 10:14

afaik, 9.0.0 was built against 1.3x which didn't have the labels support. Labels were added in 1.4x.

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