Hello everyone,
I recently started using the Appwrite cloud service and was experimenting with its functions feature.
Previously, I used AWS Lambda, and now I want to switch to Appwrite.
In AWS Lambda, you can trigger a function by sending an HTTP request to its function URL. In Appwrite, it seems we can achieve this by sending a POST request to the following URL: 'https://cloud.appwrite.io/v1/v1/functions/functionId/executions'.
However, I'm facing an issue when I try to invoke a function I created by sending a POST request using a tool like Postman. The error message I'm encountering is:
TypeError: Cannot set properties of undefined (setting 'functions') at module.exports (/usr/code-start/index.js:19:20) at /usr/local/src/server.js:68:19 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
The function works perfectly fine when I manually trigger it from the Appwrite console.
Also, I'm sending the request with all the necessary headers, including X-Appwrite-Project, Content-Type, and X-Appwrite-Key, along with a correct JSON body. Here is the demo function code I am using:
module.exports = async (req, res) => {
let options = JSON.parse(req.payload);
res.json(options);
};
Could someone please assist me in resolving this issue? Your help would be greatly appreciated.
Thank you.
FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.
What are you passing for hte JSON body?
also that url has 2 v1 in the path and you changed the function id for your actual function id, right?
where do you see this error? in the Appwrite Console function logs (errors tab)?
Hey Stevan,
Thanks for your response.
I am using the default JSON for the test
{
"firstName": "hello",
"lastName":"world",
"age":"old"
}
'also that url has 2 v1 in the path and you changed the function id for your actual function id, right? '
Yes I changed the function ID, and only v1 1 time only (added 2 v1 by mistake here)
I tried to create a new function again with the following code:
module.exports = async (req, res) => {
res.json({reqData: req,
payload: req.payload});
};
Now I am not getting the error I was getting previously, however, I noticed that the payload is always empty even though I provide a valid json body in the postman.
would you please stringify your JSON and then put this as your request body:
{
"data": "STRINGIFIED JSON"
}
see https://appwrite.io/docs/client/functions?sdk=rest-default#functionsCreateExecution
Ohh,
It Worked. Didn't know that I have to pass the stringified JSON in a data key.
Thank you so much 🙂
[SOLVED] Invoking Appwrite Functions via REST API
Hey Steven,
BTW may I know what is the max memory of appwrite cloud functions?
In AWS Lambda we can change the memory for each function from 128 mb to 3008mb.
So whats the default memory set on appwrite for functions? Or can we change it?
512mb. you can't configure it at the moment
Recommended threads
- Failed function deployments
I am using appwrite 1.8.0 (self hosted) and trying to manually deploy a python function. I am using appwrite from 0.x and went through multiple migrations. So ...
- Python-ml-3.12
Hi, when this runtime will be available for the cloud. I could see the runtimes repo has this added to Runtimes.php but I'm not able to use it to run locally or...
- Function Building show 500 Error
Region: sfo Temple: Starter Function Runtime: Nodejs 22 What happened? Before 2 minutes it show ‘server error.","code":500,"version":"0.7.24"}’ after it show c...