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
- Google Auth not working in a React App
Authentication with Google has failed. It redirects back to the signin route in React. Attached screenshots for configuration of Google console and Appwrite Go...
- How to display images from storage
I tried the link above, but it returns the error “`Please upgrade to a higher plan.`” I don’t need Transformations at the moment, I just want to display the ima...
- Cant sign up for appwrite cloud. Never s...
Cant sign up for appwrite cloud. Never sends me an email verification