Back

cloud function response error

  • 0
  • Functions
dammy
4 Jul, 2023, 16:59
TypeScript
^```

code works fine when ran independently on vscode, but I get this error when I deploy and send request from client side

I need an assistance, cause I'm sure am getting something wrong without knowing yet.
TL;DR
User is experiencing an error "Unexpected end of input" when deploying and sending a request from the client side. They are unsure of what is causing the error and need assistance. A suggestion is made to check the payload data to ensure it is valid JSON with all the necessary syntax. The user is asked to share the code for the cloud function and how they are running it. The user shares the payload data, which appears to be missing some double quotes. They also share the code for how they are creating the execution in Flutter, which seems fine. The user is asked to share how they parse the payload in the server, and they share
dammy
4 Jul, 2023, 17:00

cloud function response error

Binyamin
4 Jul, 2023, 17:03

This usually happened when the payload data is not a valid JSON. Can you print the payload data and make sure it's a valid JSON with all the double quotes, trailing comma, etc.

dammy
4 Jul, 2023, 17:07

on the cloud function or Flutter code?

besides I appreciate you for reaching out @Binyamin can't take that for granted

Binyamin
4 Jul, 2023, 17:08

In your cloud function code.

Binyamin
4 Jul, 2023, 17:09

Actually where's the error coming from? The App? Can you share the code of how you're running the function?

dammy
4 Jul, 2023, 17:09

How do I make it valid then?

dammy
4 Jul, 2023, 17:09

{numberToProcess: 62626262666 , userMail: @mail.com , userID: 649f4aa7ab7ysy4b89ba0bd , totalServiceCharge: 200 , serciceTypeAndService: 9MOBILE CG , serviceQuantity: 500MB , walletBalanceDocumentID: 12222222222, networkID: 3 , planID: 329 , serviceName: Mobile Data, customerAmount: 200 , distributorName: none, meterTypeWithID: none, cableNameWithID: none, cablePlanWithID: none}

what was printed on Flutter before sending

Binyamin
4 Jul, 2023, 17:10

What is your createExecution looks like?

dammy
4 Jul, 2023, 17:13
TypeScript
        functionId: 'automate_service_sender', data: jsonEncode(sendData));

    exec.then((response) {
      final decoded = jsonDecode(response.response);

      if (kDebugMode) {
        print("is: ${decoded.toString()}");
      }
    });
Binyamin
4 Jul, 2023, 17:14

Okay this part looks just fine.

Binyamin
4 Jul, 2023, 17:14

Can you share how you parse the payload in the server?

dammy
4 Jul, 2023, 17:18

dataFromClient = jsonDecode(req.payload);

dammy
4 Jul, 2023, 17:18

And dataFromClient was declared as dynamic

Binyamin
4 Jul, 2023, 17:18

Okay, and what do you see when you're printing the payload

TypeScript
print(req.payload);
dammy
4 Jul, 2023, 17:19

If I try to print that dart will say it does not understand the Appwrite variables and all of that

dammy
4 Jul, 2023, 17:19

So I do comment them usually

Binyamin
4 Jul, 2023, 17:19

upright?

Binyamin
4 Jul, 2023, 17:19

Meaning?

dammy
4 Jul, 2023, 17:20

When debugging from vscode

dammy
4 Jul, 2023, 17:22

Appwrite I meant @Binyamin

It was a voice to text, was walking on the road

Binyamin
4 Jul, 2023, 17:32

Comment what? req.payload should be string Can you print it, or you getting error trying to do so?

dammy
4 Jul, 2023, 17:36

Beginning from initialization of appwrite gives an error and when I change function name to main instead of start

Binyamin
4 Jul, 2023, 17:37

You can't change the name

Binyamin
4 Jul, 2023, 17:38

Make sure the function file structure it's like in the starter https://github.com/appwrite/functions-starter/blob/main/dart-2.17/lib/main.dart

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