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
- How to use appwrite types
I am using appwrite types --language ts ./types to generate the types yielding something like: ``` import type { Models } from 'node-appwrite'; // This file i...
 - Internal server Error when trying to exe...
When executing the function locally it works fine, but when the function is deployed I get this error: ```requests.exceptions.HTTPError: 500 Server Error: Inter...
 - Dynamic Roles
I tried to store a row with this permissions: permissions.push( Permission.read(Role.users("verified")), Permission.write(Role.label(`c-${calend...