Iam new to functions and i want to execute a function that triggers when the payment is made on adapty . The function should update the a attribute in user database and also there should be another function that changes the attribute again after a specific time period I have copied and changed the code from the internet , is the code correct The errror that shows in appwrite is: TypeError: userFunction is not a function at /usr/local/src/server.js:68:19 at processTicksAndRejections (node:internal/process/task_queues:96:5)
And also is there any way to test the functions locally using postman
When using Appwrite function - in current versions - it's vital to keep the Appwrite main exported function.
In your case its seems like you're using the Appwrite node function.
For that the only exported function should be something like this
const sdk = require("node-appwrite");
module.exports = async function (req, res) {
const client = new sdk.Client();
const database = new sdk.Databases(client);
// Other modules
// Function code.
res.json({'success': true});
};
As Appwrite will always try to load on function with this signature
module.exports = async function (req, res) {}
You can use Appwrite CLI To generate your functions:
https://appwrite.io/docs/command-line
appwrite init function will create your function with all necessary files then use appwrite deploy function to upload the changes to appwrite (make sure to select the function pressing the space bar)
To execute a function from postman you should send a POST request to /v1/functions/{functionId}/executions with the functionId param
Make sure your function have the right permission to be executed
I changed the code to this, but now it is showing error as:
An internal curl error has occurred within the executor! Error Msg: Operation timed out
@Binyamin What should i put in the place of endpoint
Are you using appwrite cloud?
Yes??
sorry iam not using appwrite cloud , iam using the normal functions in appwrite
Have you set the project and api and this is just an example?
Thank you for helping out, i resolved the issues
Can we trigger the function when a payment is made on adapty?
To be able to that You'll need to have a webhook towards your function. In the next Appwrite function release it will be an option, for now you'll need to use something like this https://github.com/Meldiron/railway-webhook-proxy
So even if i set webhook endpoint to the appwrite function , it wont be executed. I have to set the webook proxy using railway?
For now, yes.
Because as of now Appwrite function require you to send project ID and this part can't be done with URL variables.
Check this - in the Future possibilities section.
https://github.com/appwrite/appwrite/discussions/5016
Ok thank you very much<:appwriteheart2:1073243188954935387>
[SOLVED] Error in function execution
Recommended threads
- Realtime doesn't seem to work with Table...
Hi, I am trying to connect my tables rows with realtime on my react website, it connects, but I dont get the rows when a row is being created. I tried with Chan...
- Failed to receive appwrite reset passwor...
Hey there, I forgot my password for my appwrite account but when i use forgot password, i dont get an email to reset the account but when i try to create a new ...
- Excessive usage of cloud functions is sl...
I have made almost all my requests through cloud functions and jwt , due to security fears of a user editing a field he is not supposed to . This unfortunately...