Mosh Ontong
I am new in appwrite cloud function
This is the boilerplate code when we create new python function
TypeScript
from appwrite.client import Client
# You can remove imports of services you don't use
from appwrite.services.account import Account
from appwrite.services.avatars import Avatars
from appwrite.services.databases import Databases
from appwrite.services.functions import Functions
from appwrite.services.health import Health
from appwrite.services.locale import Locale
from appwrite.services.storage import Storage
from appwrite.services.teams import Teams
from appwrite.services.users import Users
def main(req, res):
client = Client()
# You can remove services you don't use
account = Account(client)
avatars = Avatars(client)
database = Databases(client)
functions = Functions(client)
health = Health(client)
locale = Locale(client)
storage = Storage(client)
teams = Teams(client)
users = Users(client)
if not req.variables.get('APPWRITE_FUNCTION_ENDPOINT') or not req.variables.get('APPWRITE_FUNCTION_API_KEY'):
print('Environment variables are not set. Function cannot use Appwrite SDK.')
else:
(
client
.set_endpoint(req.variables.get('APPWRITE_FUNCTION_ENDPOINT', None))
.set_project(req.variables.get('APPWRITE_FUNCTION_PROJECT_ID', None))
.set_key(req.variables.get('APPWRITE_FUNCTION_API_KEY', None))
.set_self_signed(True)
)
return res.json({
"areDevelopersAwesome": True,
})
My question here is that:
- Where I can locate the [APPWRITE_FUNCTION_ENDPOINT]?
- Do I need to create APPWRITE FUNCTION API KEY environment? and If yes, how can I create api key then?
TL;DR
1. The [APPWRITE_FUNCTION_ENDPOINT] can be located in the environment variables. Make sure it is set correctly.
2. Yes, you need to create the APPWRITE FUNCTION API KEY environment variable. To create an API key, you can follow these steps:
- Go to the Appwrite dashboard.
- Navigate to the project where you want to create the API key.
- Click on the "API Keys" tab.
- Click on the "Create Key" button.
- Give a name to your API key and choose the relevant permissions.
- Click on the "Create" button.
- Copy the Recommended threads
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...