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
Summary
There was an error in the function execution. The issue was with the Appwrite function requiring a project ID, which cannot be done with URL variables. The solution was to set up a webhook proxy using Railway. There was a question about triggering a function when a payment is made on Adapty, but it was not resolved in the thread. There was an error related to the function code, which was resolved by making sure the function had the right permissions to be executed. The thread also discussed using Appwrite CLI to generate and deploy functions. It was recommended to keep the Appwrite main 'exported' function and to check the function
Binyamin
Jun 4, 2023, 15:54
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
JavaScript
const sdk =require("node-appwrite");
module.exports=asyncfunction(req, res){
const client =newsdk.Client();
const database =newsdk.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) {}
Guille
Moderator
Jun 4, 2023, 15:58
You can use Appwrite CLI To generate your functions:
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)
Guille
Moderator
Jun 4, 2023, 15:59
To execute a function from postman you should send a POST request to /v1/functions/{functionId}/executions with the functionId param
Guille
Moderator
Jun 4, 2023, 16:01
Make sure your function have the right permission to be executed
naveen
Rank 1: Thread
Jun 4, 2023, 17:00
I changed the code to this, but now it is showing error as:
naveen
Rank 1: Thread
Jun 4, 2023, 17:00
An internal curl error has occurred within the executor! Error Msg: Operation timed out
naveen
Rank 1: Thread
Jun 4, 2023, 17:21
@Binyamin What should i put in the place of endpoint
Susmita
Rank 3: Container
Jun 4, 2023, 17:30
Are you using appwrite cloud?
naveen
Rank 1: Thread
Jun 4, 2023, 17:30
Yes??
naveen
Rank 1: Thread
Jun 4, 2023, 17:42
sorry iam not using appwrite cloud , iam using the normal functions in appwrite
Binyamin
Jun 4, 2023, 18:17
Have you set the project and api and this is just an example?
naveen
Rank 1: Thread
Jun 4, 2023, 18:47
Thank you for helping out, i resolved the issues
naveen
Rank 1: Thread
Jun 4, 2023, 18:48
Can we trigger the function when a payment is made on adapty?
Binyamin
Jun 4, 2023, 18:50
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
naveen
Rank 1: Thread
Jun 4, 2023, 19:21
So even if i set webhook endpoint to the appwrite function , it wont be executed. I have to set the webook proxy using railway?
Binyamin
Jun 4, 2023, 19:25
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.