
I am writing the function in dart language. I want to get the data when the document is created. However I don’t know how can I get the JSON data from APPWRITE_FUNCTION_EVENT_DATA.
Anyone use Dart language to advise me.
Thanks

Do you not get the data from the response? Are you using cloud or self hosted? Also can you share your function code?

I used cloud platform.
Here is my code.
Map<String, String> envVars = Platform.environment;
final payload = jsonDecode(envVars['APPWRITE_FUNCTION_EVENT_DATA']!);
I got the error when the event is triggered. Here is the error message.
Null check operator used on a null value
#0 main (package:starter_template/main.dart:39)
#1 main.<anonymous closure>.<anonymous closure> (file:///usr/local/server/src/server.dart:115)
#2 _rootRun (dart:async/zone.dart:1399)
#3 _CustomZone.run (dart:async/zone.dart:1301)
#4 _runZoned (dart:async/zone.dart:1804)
#5 runZoned (dart:async/zone.dart:1747)
#6 main.<anonymous closure> (file:///usr/local/server/src/server.dart:110)
<asynchronous suspension>
#7 handleRequest (package:shelf/shelf_io.dart:138)
<asynchronous suspension>

If I remember, the event data is now get from context.req.body
, if isn't try looking the req
object

Have you checked your environment variable APPWRITE_FUNCTION_EVENT_DATA
? Can you print out the envVars
has data

I print context.req.body. It looks like not the json format.
The envVars['APPWRITE_FUNCTION_EVENT_DATA'] is null
context.req.body is {name: ghhh, phone: 25852588, email: yyg@bhg.bvg, gender: M, church: ghh, yearInHIM: 22, yearInBaptist: 2585, churchService: , yearInChurchChoir: , otherChoir: , yearInOtherChoir: , part: , musicTalent: , otherTalent: , $id: 0AAwOPZM8b25852588, $permissions: [read("user:658438032da8455c4141"), update("user:658438032da8455c4141"), delete("user:658438032da8455c4141")], $createdAt: 2023-12-21T13:33:11.792 00:00, $updatedAt: 2023-12-21T13:33:11.792 00:00, isEmail: false, $databaseId: default, $collectionId: applicationList}
envVars['APPWRITE_FUNCTION_EVENT_DATA'] is null

I meant print out all the environment variables envVars
and check, it could be a typo issue

Yes. I print all for environment variables envVars. However I can’t find the key “APPWRITE_FUNCTION_EVENT_DATA”. Where is the event data?
APPWRITE_API_KEY
APPWRITE_FUNCTION_RUNTIME_NAME
HOSTNAME
HOME
OLDPWD
APPWRITE_FUNCTION_API_KEY
FROM_ADDRESS
TO_ADDRESS
EMAIL_SUBJECT
PATH
APPWRITE_FUNCTION_NAME
SENDGRID_API_KEY
INERNAL_EXECUTOR_HOSTNAME
OPEN_RUNTIMES_ENTRYPOINT
APPWRITE_FUNCTION_RUNTIME_VERSION
APPWRITE_FUNCTION_ENDPOINT
APPWRITE_FUNCTION_ID
DART_SDK
PWD
OPEN_RUNTIMES_HOSTNAME
APPWRITE_FUNCTION_DEPLOYMENT
APPWRITE_FUNCTION_PROJECT_ID
OPEN_RUNTIMES_SECRET

Since 1.4, they should be in context.req.body. And it should be decoded for you already (so it's a Map)

You can find all information related to functions in v1.4 here: https://appwrite.io/docs/products/functions/development
Recommended threads
- my database attribute stuck in processin...
when i created attributes in collection 3 of those attributes become "processing", and they are not updating, the worst thing is that i cant even delete them s...
- Is Quick Start for function creation wor...
I am trying to create a Node.js function using the Quick Start feature. It fails and tells me that it could not locate the package.json file. Isn't Quick Start ...
- Forever Processing Issue
I encountered an issue when creating attributes in the collections . if you create an attribute of type string for example and choose a size of 200 or 250 or a...
