
Hi there,
I am new to Appwrite, and am trying to make a database storing a number associated with the userId. Here is my code.
Function call(Javascript) const payload = JSON.stringify({context: context, function:'get', userId: userId, amount: amount }); const result = await functions.createExecution("6770291b00171ec2611b", payload);
Function Code(Python): from appwrite.client import Client from appwrite.services.users import Users from appwrite.services.databases import Databases from appwrite.exception import AppwriteException import os key = os.API_KEY
This Appwrite function will be executed every time your function is triggered
def main(context,function, userId, amount): # You can use the Appwrite SDK to interact with other services # For this example, we're using the Users service client = ( Client() .set_endpoint('https://cloud.appwrite.io/v1') .set_project('67609b010021900fc6e6') .set_key(key) ) users = Users(client) databases = Databases(client) if(function == "get"): result = databases.get_document('6760b9c20030df251f1c','badgerBucks', userId) return res.result['badgerBucks'] elif(function == "set"): databases.update_document('6760b9c20030df251f1c','badgerBucks', userId, {'username': userId, 'badgerBucks': amount}) elif(function == "create"): database.creat_document('6760b9c20030df251f1c','badgerBucks',userId,{'username':userId,'badgerBucks':amount})
I am wondering if I should use the context parameter instead of the function parameter. I could not find much on the docs about how and what to use the context parameter for.
Thanks in advance,
-sharmnten

EDIT: the markdown formatting of discord messed up the some of the comments. Apologies.

Functions need to have a specific default entrypoint that accepts just the context
object or the de-structured objects within if the runtime supports it.
The context
in all runtimes contain 4 vars.
Request, Response, Log & Error.
See - https://appwrite.io/docs/products/functions/develop#context-object
Recommended threads
- 1.7.x Style issue in the migration page
I am not able to select what to migrate because of the styling... the checkboxes are not showing on any of the appwrite versions 1.7.x. I tried other browsers, ...
- Appwrite Sites: Max File Size
Hello, I am facing an issue on my self-hosted appwrite instance with Appwrite Sites. I already have a small vite web app built out that I want to deploy, and ...
- Webhooks not working?
I have this webhook in appwrite but unfortunately this webhook isn't being triggered whenever I change something in the database. I've put the right databaseID ...
