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
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...
- custom domain with CloudFlare
Hi all, it seems that CloudFlare has blocked cross-domain CNAME link which made my app hostname which is in CloudFlare, unable to create a CNAME pointing to clo...
- Custom emails
What happen if I use a third party email provider to customize my emails and my plan run out of emails/month? Appwrite emails are used as fallback sending emai...