Rank 1: Thread
I am writing an app with flutter. On user.create : a function is triggered to create a document. I understand with users.create trigger, the whole "user" object is passed as payload to the function. So I guess it means I can get all the info about user I need within the function.
I am faced with syntax problem and just can't figure it out with the docs. (I am a beginner).
Can someone help me understand how : I connect the function to the cloud project (I see different syntaxes in different examples), then how I actually get the "payload" with the user object : what is the syntax to get the info...
I am a bit lost.... So here is the code I used so far. My question : where and how do get the info about the user ? import 'dart:io';
import 'dart:async';
import 'package:dart_appwrite/dart_appwrite.dart';
Future main(final context) async {
final client = Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject(Platform.environment['APPWRITE_FUNCTION_PROJECT_ID'])
.setKey(Platform.environment['APPWRITE_API_KEY']);
final databases = Databases(client);
try {
await databases.createDocument(
databaseId: '[DATABASE_ID]',
collectionId: '[COLLECTION_ID]',
documentId: ID.unique(),
data: {}
);
} catch (e) {
context.error("Failed to create document: " + e.message);
return context.res.send("Failed to create document");
}
return context.res.send("Document created");
}