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
- Failed function deployments
I am using appwrite 1.8.0 (self hosted) and trying to manually deploy a python function. I am using appwrite from 0.x and went through multiple migrations. So ...
- Skip total counts crash the query
Hello, When adding the total parameter (either true, the default, or false) to the listRows function, it raises the following error: `type 'bool' is not a sub...
- Relationships and Realtime
Since now Relationship attributes are only returned when explicitly queried, how does this change reflect in Realtime? If a listener is listening to a row from ...