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
- HTTP POST to function returning "No Appw...
Hi everyone, I’m running into an issue with my self-hosted Appwrite instance. I’ve set up my environment variables (APPWRITE_FUNCTION_PROJECT_ID, APPWRITE_FUNC...
- Can't add dart 3.5 runtime
Modified the `.env` to enable dart 3.5 runtime on my self-hosted instance but still can't find the runtime when creating a new function. I manually pulled the i...
- How to verify an user using AppWrite Fun...
I have seen similar questions but none whose solutions serve me. I have a function to verify a user with their secret and their id: https://blahblah.appwrite.gl...