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
- Download appwrite Docs
Is there is a way to download appwrite Docs ? Because appwrite skill isn't enough to give the agent full understanding about how appwrite works (I noticed this ...
- Appwrite Cloud Project shutdown due to i...
My appwrite projects gets shut down saying due to inactivity, but our platform gets users everyday with many requests to database and storage. so why all of a s...
- Local appwrite run functions --user-id n...
Hi, I'm running into an issue when testing Appwrite functions locally with user impersonation. I'm using a self-hosted Appwrite instance and running functions ...