
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
- error code:524 for functions running lon...
We are having this issue, no longer the function runtime or code, if it goes longer than 1 minute, there's no logs at all, just this error: **error code: 524**
- Invalid `specification` param: Specifica...
I'm self-hosting my appwrite instance on my Macbook, and I created a Python function using the command `appwrite init functions` and it outputed the below into ...
- Local function throws EACCES error when ...
I am developing an Appwrite function locally. Up until now, the process has been as smooth as butter: I edit my files, save them, and this triggers a rebuild of...
