In my cloud function I have this context.res.json({..}). Now in Dart how to get the json response? in Flutter
Create a sync execution and then the result should have it
final execution = await functions.createExecution(
functionId: functionId,
body: jsonEncode(mapTracking.toAppwriteDocument()),
xasync: false,
path: '/',
method: 'POST',
headers: {
'content-type': 'application/json',
},
);
set the xasync into false?
correct
hello, @Mosh Ontong can you please share the code entry and decoding the user request.
I just saw how you sent user response using
context.res.json({..})
In my dart function:
Future<dynamic> main(final context) async {
final client = Client();
final database = Databases(client);
final users = Users(client);
if (Platform.environment['APPWRITE_FUNCTION_ENDPOINT'] == null ||
Platform.environment['APPWRITE_FUNCTION_API_KEY'] == null) {
context.error(
"Environment variables are not set. Function cannot use Appwrite SDK.");
} else {
client
.setEndpoint(Platform.environment['APPWRITE_FUNCTION_ENDPOINT']!)
.setProject(Platform.environment['APPWRITE_FUNCTION_PROJECT_ID'])
.setKey(Platform.environment['APPWRITE_FUNCTION_API_KEY']);
}
if (context.req.method == 'POST') {
final payload = context.req.body as Map<String, dynamic>;
.....
}}
And this is how I execute the function and get the response
final execution = await functions.createExecution(
functionId: functionId,
body: jsonEncode(
{
'documentId': serviceId,
'ratings': totalRating,
},
),
xasync: false,
path: '/',
method: 'POST',
headers: {
'content-type': 'application/json',
},
);
_logger.info('Successfully created bookTrace: $execution');
final response =
jsonDecode(execution.responseBody) as Map<String, dynamic>;
thanks @Mosh Ontong
I still get client side error
@Mosh Ontong Please will you be available for a 5 mins virtual assistance, a getting so many things wrong
please someone should help, I ave been on this for days
What is your code & error?
Recommended threads
- Function executions fail with cURL error...
Appwrite version: 1.8.0 Executor version: 0.11.4 Function runtime: Python 3.12 SELF-HOSTED Function executions that occur at the same moment as the executor's ...
- Broken Appwrite canโt make functions nor...
Hii guys, I was having this issue with my locally hosted Appwrite, I canโt create functions ( both template and manual), I canโt make a custom domain ( like in ...
- Tips for Debugging Appwrite Functions Lo...
Hi everyone! ๐ I have an Appwrite Function running locally with Docker, but Iโm struggling to debug it because execution doesnโt reach the breakpoints I set. ...