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
- Seed db
hello there... is this correct way to seed appwrite
- Need help with createExecution function
Hi, Need some help understanding createExecution. When requesting function execution via createExecution, the function handler arguments are incorrect and rese...
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?