This is my python function, and I'm not sure why it fails when run it in console What am I doing wrong?
def main(req, res):
payload = req.payload or 'No payload provided. Add custom data when executing function.'
secretKey = req.variables.get(
'API_KEY_HERE',
'SECRET_KEY variable not found. You can set it in Function settings.'
)
client = Client()
(client
.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
.set_project('PROJECT_ID_HERE') # Your project ID
.set_key('API_KEY_HERE') # Your secret API key
)
databases = Databases(client)
result = databases.create_document('DATABASE_ID_HERE', 'COLLECTION_ID_HERE', 'ID.unique()', {
'Name': 'user123',
'Logo': 'https://images1-fabric.practo.com.png',
'Title': 'title123',
'Location': 'loc1'
},)
return res.json({
'message': 'Hello from Appwrite!',
'payload': payload,
'result': result
})
What is the error? Also maybe the ID shouldn't be a string?
result = databases.create_document('DATABASE_ID_HERE', 'COLLECTION_ID_HERE', ID.unique(), {
'Name': 'user123',
'Logo': 'https://images1-fabric.practo.com.png',
'Title': 'title123',
'Location': 'loc1'
},)
if its outside the string, it says "ID" is not defined
also, in the docs it says string (assuming I'm not misinterpreting it)
Add this at the top of your document
from appwrite.id import ID
Interesting, What is the error you're getting?
there's nothing in errors/ logs
leme try that
failed again😫
For this also set the ID.unique() as a function?
yeah, did that
Ohh, I'm sorry How did you try to execute the function?
um from the console
In Appwrite or a terminal?
appwrite
Do you any information in any of these tabs?
nope
they just empty
Just want to be sure all the string ends with *_HERE was changed by you for the example, yes?
yeah
Okay, let's try to put all the code inside try/catch block to see what is the exception if there is one.
try:
...your code
except Exception as e:
return res.json({"success": False, "message": str(e)})
After running your code like such you'll be able to see the error message in the Response tab in the console.
okay let me try this
Recommended threads
- Permissions error
I try to create a row in my table but when i submit i have an error on my permission, i'm new on it so i dont understand the error. I have Row Security enable ...
- Console: Query on attribute has greater ...
I noticed an issue when one of my tables reached over ~800 rows. That table is relational to my users table Within the console I am able to view the table with ...
- Appwrite 1.8.1 TablesDB Permissions Issu...
Hi - I'm migrating a newer VueJS web application from Supabase to Appwrite. I'm looking for an experienced Appwrite Developer to help me solve a permissions iss...