Back

Cloud function Invalid status: Value must be a valid boolean

  • 0
  • Users
  • Functions
mickybizzle
25 Jul, 2023, 08:35

Hi all. Looking for some assistance with cloud functions.

When a new user is created I want to add a isNew: true preference to their account. Code below

TypeScript
module.exports = async function (req, res) {
  const client = new sdk.Client();
  const users = new sdk.Users(client);

  const userId = JSON.parse(req.variables.APPWRITE_FUNCTION_EVENT_DATA).$id;

  if (
    !req.variables["APPWRITE_FUNCTION_ENDPOINT"] ||
    !req.variables["APPWRITE_FUNCTION_API_KEY"]
  ) {
    console.warn(
      "Environment variables are not set. Function cannot use Appwrite SDK."
    );
  } else {
    client
      .setEndpoint(req.variables["APPWRITE_FUNCTION_ENDPOINT"])
      .setProject(req.variables["APPWRITE_FUNCTION_PROJECT_ID"])
      .setKey(req.variables["APPWRITE_FUNCTION_API_KEY"])
      .setSelfSigned(true);
  }

  users
    .updateStatus(userId, { isNew: true })
    .then((result) => {
      res.json({ success: true, message: result });
    })
    .catch((err) => {
      res.json({ success: false, message: err });
    });
};

This is the response I am getting

TypeScript
{
  "success": false,
  "message": {
    "code": 400,
    "type": "general_argument_invalid",
    "response": {
      "message": "Invalid status: Value must be a valid boolean",
      "code": 400,
      "type": "general_argument_invalid",
      "version": "1.3.8"
    }
  }
}

I have tried looking through previous issues but nothing has helped so far. What am I missing?

TL;DR
The user was mistakenly calling the `users.updateStatus` function instead of `users.updatePrefs`, which caused the error "Invalid status: Value must be a valid boolean." They identified and fixed the issue by correcting the function call.
mickybizzle
25 Jul, 2023, 10:26

Well I feel stupid! I just noticed I was calling users.updateStatus and not users.updatePrefs I'll blame github co-pilot for autocompleting to make me feel better. It works as expected. Closing this issue.

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