Hey I made a python cron function that's just adding values to collection, but when I deploy it, I get this error
import json
import pandas as pd
from appwrite.client import Client
from appwrite.services.databases import Database
def init_client():
# Initialize the Appwrite client
client = Client()
client.set_endpoint("https://cloud.appwrite.io/v1")
client.set_project("646769a1263324aecec0")
client.set_key("API_KEY")
return client
def main():
client = init_client()
database = Database(client)
database.create_document("646a552f4564180c1531", {
'company_name': "Utopia",
'job_title': "Software Engineer",
'about_company': "Utopia is a software company that builds software for the future",
'location': "Remote",
'skills_required': "Python, Java, C++",
'job_responsibilities': "Build software for the future",
'job_requirements': "Must have 5 years of experience",
'logo': "https://www.utopia.com/logo.png"
}, read=['*'])
if __name__ == "__main__":
main()```
Error:
This doesn't look like the right structure for an Appwrite Function. Make sure to follow the docs: https://appwrite.io/docs/functions
Oh I followed this repo, is it not updated or something? https://github.com/appwrite/demos-for-functions/blob/master/python/create_user_profile/main.py
also, according to the docs, is it necessary to return a res, cause I just want this function to directly update values in the collection?
Am I doing something wrong, even this is not deploying😫
def main(req, res):
payload = req.payload or 'No payload provided. Add custom data when executing function.'
secretKey = req.variables.get(
'api_key,
'SECRET_KEY variable not found. You can set it in Function settings.'
)
randomNumber = random.random()
# trigger = req.variables['APPWRITE_FUNCTION_TRIGGER']
return res.json({
'message': 'Hello from Appwrite!',
'payload': payload,
'secretKey': secretKey,
'Number': 123,
})```
That repo is archived
I highly recommend using the Appwrite CLI to initialize and deploy the starter python function. Then, you can tweak it accordingly
Recommended threads
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...