Rank 3: Container
yes
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 3: Container
yes
Admin
Okay it should be the same then
Rank 3: Container
for checking how can i print payload in console or log
Admin
Use print() but make sure to pass it a string
Rank 3: Container
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
}```
Rank 3: Container
payload is not printing in response nor in console, print( response.json(payload.toString())); print(payload.toString());
Admin
Why are you calling response.json() like that?
Admin
Also your error could be happening before the print
Rank 3: Container
not using that
Admin
Sorry, what?
Rank 3: Container
just mistakenly copied, trying to see whether it prints on response section or not( or happening something in console).
Rank 3: Container
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"}
Admin
And your file is named main.dart? If so, the problem is around line 10
Rank 3: Container
yes
Rank 3: Container
here is file structure
Rank 3: Container
also change function name (at line 10) main to mainfunc but still giving the same error
Admin
Wait line 10 was the function name?
Admin
It should be start...
Rank 3: Container
yes its function name define inside ServerAppwrite class
Rank 3: Container
do you mean i have to define main then call this start inside main, right ?
Rank 3: Container
why its printing Environment variables are not set. Function cannot use Appwrite SDK. executing this function in appwirte console ```Future 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,
});
}```
Admin
Did you create the variable?
Rank 3: Container
after creating the variable its working fine,
Rank 3: Container
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());
Admin
req doesn't have payloads. It's payload