After executing my function in dart, im getting
An internal curl error has occurred within the executor
All I added to the function is
final listUser = await users.list();
listUser.users.forEach(print);
I also added APPWRITE_FUNCTION_ENDPOINT and APPWRITE_FUNCTION_API_KEY to the function, the apikey has the users.read permission. Am I missing something?
` Future<void> start(final req, final res) async { final client = Client();
// Uncomment the services you need, delete the ones you don't // final account = Account(client); // final avatars = Avatars(client); // final database = Databases(client); // final functions = Functions(client); // final health = Health(client); // final locale = Locale(client); // final storage = Storage(client); // final teams = Teams(client); final users = Users(client);
final listUser = await users.list();
listUser.users.forEach(print);
if (req.variables['APPWRITE_FUNCTION_ENDPOINT'] == null || req.variables['APPWRITE_FUNCTION_API_KEY'] == null) { print( "Environment variables are not set. Function cannot use Appwrite SDK."); } else { client .setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT']) .setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID']) .setKey(req.variables['APPWRITE_FUNCTION_API_KEY']) .setSelfSigned(status: true); }
res.json({ 'areDevelopersAwesome': true, }); } ` Full dart function
First assignment as variable in your client then you can call final listUser = await users.list();
listUser.users.forEach(print);
please follow example from documentation <:appwritepeepo:902865250427215882> : https://appwrite.io/docs/functions#writingYourOwnFunction
better this one: https://github.com/appwrite/playground-for-dart/blob/main/main.dart
what do you mean with assigne as variable
FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.
You're calling users.list() before actually setting the endpoint and api key so users.list() throws an error and fails with the error message you shared.
make sure to initialize client first.
In addition, try to make sure your code doesn't throw any exceptions and res.json() is called exactly once
Hey, thanks for the answer. Why exactly do I need to specify the endpoint, the projectid and the key in this case? Isnt the function run in the backend, shouldnt it already have acceess to those things automatically? Or is it because it run in its separete container
Maybe I'm missing something here. Also, is it safe to just hard code the api key into my cloud function?
Or should these values be set as envs for the function?
nvm, I can answer my question my self, I just gotta read the else in code, which litrally takes the data out of the env and initilizes the client. Now I see, thanks 😄
Recommended threads
- [SOLVED] curl error Number: 6 — function...
Hello, I invested a lot of time in this error in a fresh install of appwrite 1.8.1 and lasted until fix, this if for helping anyone that can have the same weird...
- android platform invaild origina
It happened today suddenly. Our app says invalid origin. And appwrite cloud says every time we tried to add the app to it: "param platformId" is not optional.
- Team invite - 500 error - no email
When executing ```dart await _repository.teams.createMembership( teamId: event.listId, roles: ['member'], email: event.email, url: 'xxxx', ); ``` I se...