Back

Where is APPWRITE_FUNCTION_EVENT_DATA for dart language in function

  • 0
  • Functions
  • Cloud
Patrick Lee
21 Dec, 2023, 09:58

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

TL;DR
The user is asking for help with the `APPWRITE_FUNCTION_EVENT_DATA` in Dart language. They have checked their environment variables and `envVars['APPWRITE_FUNCTION_EVENT_DATA']` is null. They are trying to access the data in `APPWRITE_FUNCTION_EVENT_DATA` but getting a null error. The error seems to be occurring when the event is triggered. They are using a cloud platform. Possible solution: - Make sure that the `APPWRITE_FUNCTION_EVENT_DATA` environment variable is properly set and accessible. - Print out the `envVars` variable to check if it contains any data. - Check if the
Ernest
21 Dec, 2023, 10:29

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

Patrick Lee
21 Dec, 2023, 11:10

I used cloud platform.

Here is my code.

TypeScript
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.

TypeScript
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>
Guille
21 Dec, 2023, 13:10

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

Ernest
21 Dec, 2023, 13:11

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

Patrick Lee
21 Dec, 2023, 13:36

I print context.req.body. It looks like not the json format.

The envVars['APPWRITE_FUNCTION_EVENT_DATA'] is null

TypeScript
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
Ernest
21 Dec, 2023, 13:39

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

Patrick Lee
21 Dec, 2023, 13:46

Yes. I print all for environment variables envVars. However I can’t find the key “APPWRITE_FUNCTION_EVENT_DATA”. Where is the event data?

TypeScript
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
Drake
21 Dec, 2023, 17:05

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

Guille
22 Dec, 2023, 11:52

You can find all information related to functions in v1.4 here: https://appwrite.io/docs/products/functions/development

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more