Failing to execute functions: Error Msg:{"error":"type 'Null' is not a subtype of type 'String'"}
- 0
- Flutter
- Functions

yes

Okay it should be the same then

for checking how can i print payload in console or log

Use print()
but make sure to pass it a string

here is raw data ```{ "$id": "6452d0f3ce9edca1866d", "$createdAt": "2023-05-05T23:56:37.807+00:00", "$updatedAt": "2023-05-06T00:37:35.262+00:00", "execute": [
], "name": "func", "enabled": true, "runtime": "dart-2.17", "deployment": "6455a13c9026fb596952", "vars": [
], "events": [
], "schedule": "", "scheduleNext": "", "schedulePrevious": "", "timeout": 15 }```

payload is not printing in response nor in console, print( response.json(payload.toString()));
print(payload.toString());

Why are you calling response.json() like that?

Also your error could be happening before the print

not using that

Sorry, what?

just mistakenly copied, trying to see whether it prints on response section or not( or happening something in console).

here is the trace {"error":"type 'Null' is not a subtype of type 'String'#0 start (package:appwrite_function\/main.dart:10)\n#1 main.<anonymous closure>.<anonymous closure> (file:\/\/\/usr\/local\/src\/server.dart:37)\n#2 main.<anonymous closure>.<anonymous closure> (file:\/\/\/usr\/local\/src\/server.dart:36)\n#3 _rootRun (dart:async\/zone.dart:1426)\n#4 _CustomZone.run (dart:async\/zone.dart:1328)\n#5 _runZoned (dart:async\/zone.dart:1861)\n#6 runZonedGuarded (dart:async\/zone.dart:1849)\n#7 main.<anonymous closure> (file:\/\/\/usr\/local\/src\/server.dart:35)\n<asynchronous suspension>\n#8 handleRequest (package:shelf\/shelf_io.dart:138)\n<asynchronous suspension>\n"}

And your file is named main.dart? If so, the problem is around line 10

yes

here is file structure

also change function name (at line 10) main to mainfunc but still giving the same error

Wait line 10 was the function name?

It should be start...

yes its function name define inside ServerAppwrite class

do you mean i have to define main then call this start inside main, right ?

why its printing Environment variables are not set. Function cannot use Appwrite SDK. executing this function in appwirte console ```Future<void> start(final req, final res) async { final client = Client();
// Uncomment the services you need, delete the ones you don't // final account = Account(client); // final avatars = Avatars(client); // final database = Databases(client); // final functions = Functions(client); // final health = Health(client); // final locale = Locale(client); // final storage = Storage(client); // final teams = Teams(client); // final users = Users(client);
if (req.variables['APPWRITE_FUNCTION_ENDPOINT'] == null || req.variables['APPWRITE_FUNCTION_API_KEY'] == null) { print( "Environment variables are not set. Function cannot use Appwrite SDK.");
} else { client .setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT']) .setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID']) .setKey(req.variables['APPWRITE_FUNCTION_API_KEY']) .setSelfSigned(status: true); }
res.json({ 'areDevelopersAwesome': true, }); }```

Did you create the variable?

after creating the variable its working fine,

trying to print payload but if i add print statement then function execution is failed saying An internal curl error has occurred within the executor! Error Msg:
Operation timed out
other wise its working fine, this is how using print
print(req.payloads.toString());

req
doesn't have payloads
. It's payload
Recommended threads
- Accessing caller UserID on Function Exce...
I'm working with function, which should generate a document in Collection B, but only if user who's calling the function, is the owner of Document in Collection...
- Steps to Enable HTTP Access to appwrite ...
Hi Appwrite team, I have created a function and I want it to receive and incoming post request from a webhook( a webhook that notifies the function to update t...
- Unable to Access Appwrite Console & API ...
I have been unable to access my Appwrite console and related services for the past two weeks. Additionally, the Appwrite integration on my production website ha...
