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
- Worker functions stuck on "Fetched 0 fun...
Appwrite Version: 1.9.0 Bug Description: The appwrite-worker-functions container gets stuck in an infinite loop logging "Fetched 0 functions..." while scheduled...
- I am using s3 for app storage but is it ...
_APP_STORAGE_DEVICE=s3 puts everything to the s3 storage but i need to be able to keep the function builds and site in the local and not waste the cloud storage...
- Local Serverless Function Testing: Are D...
I have followed the instructions to get the CLI working, and have been able to log-in, initialize my project, and created a simple Python function, which calls ...