Back

[SOLVED] Error in function execution

  • 0
  • Functions
  • Web
naveen
4 Jun, 2023, 14:49

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

TL;DR
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
4 Jun, 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

TypeScript
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

TypeScript
module.exports = async function (req, res) {}
Guille
4 Jun, 2023, 15:58

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)

Guille
4 Jun, 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
4 Jun, 2023, 16:01

Make sure your function have the right permission to be executed

naveen
4 Jun, 2023, 17:00

I changed the code to this, but now it is showing error as:

naveen
4 Jun, 2023, 17:00

An internal curl error has occurred within the executor! Error Msg: Operation timed out

naveen
4 Jun, 2023, 17:21

@Binyamin What should i put in the place of endpoint

Susmita
4 Jun, 2023, 17:30

Are you using appwrite cloud?

naveen
4 Jun, 2023, 17:30

Yes??

naveen
4 Jun, 2023, 17:42

sorry iam not using appwrite cloud , iam using the normal functions in appwrite

Binyamin
4 Jun, 2023, 18:17

Have you set the project and api and this is just an example?

naveen
4 Jun, 2023, 18:47

Thank you for helping out, i resolved the issues

naveen
4 Jun, 2023, 18:48

Can we trigger the function when a payment is made on adapty?

Binyamin
4 Jun, 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
4 Jun, 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
4 Jun, 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.

Check this - in the Future possibilities section. https://github.com/appwrite/appwrite/discussions/5016

naveen
4 Jun, 2023, 19:28

Ok thank you very much<:appwriteheart2:1073243188954935387>

Drake
4 Jun, 2023, 21:18

[SOLVED] Error in function execution

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more