I have created a cloud function but it is not working on appwrite cloud. It should trigger on the event - User successfully verified phone number To do - create a new user document in database. My code -
`import json from appwrite.client import Client from appwrite.services.databases import Databases
def main(req, res): client = Client()
(client
.set_endpoint('https://cloud.appwrite.io/v1')
.set_project('[MY_PROJECT_ID]')
.set_key('[MY_KEY]')
)
databases = Databases(client)
payload = json.loads(req.payload)
result = databases.create_document('[MY_DATABASE_ID]', '[MY_COLLECTION_ID]', ID.unique(), {
'name': payload['name'],
'mobileNo': payload['phone'],
'uid': payload['uid'],
},)
res.json({result})
`
Did you set the variables in your Appwrite project. Like the Database Id, Project Id, and API Key? You can check out the video. Something like that.
Additionally you can also review your function deployments and execution logs to confirm if the function was successfully deployed or if there is any error in the function execution
in the logs it is showing error as Unexpected curl error between proxy and executor: Connection reset by peer
You are using appwrite cloud beta, true? Or appwrite self-host/localhost?
appwrite cloud beta
For functions triggered by event, the payload will be an empty string and your function will throw an exception.
In general, make sure your function never throws an exception and make sure to call res.json or res.send exactly once before returning
thank u very much sir... but then how to get the payload sir as soon as the user is created?
You'll need to check a second variable named APPWRITE_FUNCTION_EVENT_DATA this one will contain all the event data, something like this
try{
final event = json.loads(req.variables["APPWRITE_FUNCTION_EVENT_DATA"])
} catch(e){
// handle error
}
Thank you all for the help
[SOLVED] Appwrite Cloud function not working
Recommended threads
- Appwrite-injected variables are not avai...
I am using rust-1.83 as a runtime and try to access APPWRITE_FUNCTION_API_ENDPOINT or APPWRITE_FUNCTION_API_KEY during runtime. Both are not set during my execu...
- Appwrite (Dart SDK) (for package_info_pl...
Hi team! Many Flutter plugins now need package_info_plus 10.x and device_info_plus 13.x, but appwrite 25.4.0 still constrains package_info_plus: >=8.0.2 <10.0...
- Functions in cloud console not works
please advise as all of my runing functions on Appwrite console was working before , but now it give this error [Invalid `headers` param: Value must be a valid...