Skip to content
Back

[Solved] Empty Body on cURL Request

  • 0
  • Functions
williamCardoso
18 Sep, 2023, 15:44

Hello everyone, Can someone help me on identifying what's wrong with my curl request? It works fine If I try through Console

TypeScript
{
curl --request POST \
  --url http://MY_MACHINE_IP_LOCALHOST:80/v1/functions/MY_FUNCTION_ID/executions \
  --header 'Content-Type: application/json' \
  --header 'X-Appwrite-Key: MY_APPWRITE_KEY' \
  --header 'X-Appwrite-Project: MY_PROJECT_ID' \
  --data '{
  "data": "{\"sender\":\"valid@mail.com\",\"body\":\"<!DOCTYPE html><html><head><title>Mensagem HTML Simples</title></head><body><h1 style=\\\"color: blue;\\\">Mensagem HTML Simples</h1><p>Esta é uma mensagem HTML de exemplo.</p><p>Você pode personalizá-la como desejar.</p></body></html>\",\"subject\":\"Testing Email Sending with Functions\",\"recipients\":[{\"email\":\"valid@mail.com\",\"name\":\"William Cardoso\"}]}"
}
'

My requests throws error since no data is recognized. How to properly execute it? I am using Insomnia

TL;DR
The user is having trouble with an empty body on a cURL request in Insomnia. They are specifically using Appwrite and Dart Runtime 3.0. They have tried different variations of the cURL request and different data inputs, but they keep getting an error that the body is empty. They are seeking help to identify the issue. Solution: The user should remove the ":80" from the cURL request URL.
Binyamin
18 Sep, 2023, 15:46

Try to remove the :80 Like so

TypeScript
--url http://MY_MACHINE_IP_LOCALHOST/v1/functions/MY_FUNCTION_ID/executions \
williamCardoso
18 Sep, 2023, 15:48

Yeah still gives the same error. Also, I tried sending a simple data imaging maybe something is wrong with my data, but also gives same error: data is empty.

Also, it is reaching console since it is listing the failed executions there. I just can't understand why data/body is going empty since I am defining it.

Binyamin
18 Sep, 2023, 15:49

What response you're getting?

williamCardoso
18 Sep, 2023, 15:52

Even with: '{"data":"this is json data"}'

I am getting:

TypeScript
"errors": "On Catch FormatException: Unexpected end of input (at character 1)\n\n^\n\nStacktrace #0      _ChunkedJsonParser.fail (dart:convert-patch\/convert_patch.dart:1383)\n#1      _ChunkedJsonParser.close (dart:convert-patch\/convert_patch.dart:501)\n#2      _parseJson (dart:convert-patch\/convert_patch.dart:36)\n#3      JsonDecoder.convert (dart:convert\/json.dart:610)\n#4      JsonCodec.decode (dart:convert\/json.dart:216)\n#5      jsonDecode (dart:convert\/json.dart:155)\n#6      main (package:dispatch_email\/main.dart:23)\n#7      main.<anonymous closure>.<anonymous closure> (file:\/\/\/usr\/local\/server\/src\/server.dart:115)\n#8      _rootRun (dart:async\/zone.dart:1399)\n#9      _CustomZone.run (dart:async\/zone.dart:1301)\n#10     _runZoned (dart:async\/zone.dart:1804)\n#11     runZoned (dart:async\/zone.dart:1747)\n#12     main.<anonymous closure> (file:\/\/\/usr\/local\/server\/src\/server.dart:110)\n<asynchronous suspension>\n#13     handleRequest (package:shelf\/shelf_io.dart:138)\n<asynchronous suspension>\n",

When I console log the context.req.body (I am using Dart Runtime 3.0) It shows that the body is empty, that's why I am getting error trying to decode it.

I am trying to figure out what change in cURL format from 1.1.2 to 1.4.2 since it works on my previous implementation on 1.1.2

Here a post I've made about it: https://dev.to/williamcardoso/sending-emails-with-dart-and-appwrite-serverless-functions-3dmj

I am updating to 1.4.2

Binyamin
18 Sep, 2023, 15:54

Gotch Try to send it like so

TypeScript
--data '{
  \"data\": \"{\"
Binyamin
18 Sep, 2023, 15:54

Meaning add \ to all double quotes

williamCardoso
18 Sep, 2023, 15:57

Still nothing :/ but thanks for your help

williamCardoso
18 Sep, 2023, 15:58

It is interesting that the same cURL works for mine 1.1.2 Appwrite Function

Binyamin
18 Sep, 2023, 15:58

The problem is that your Dart function can't convert this json

williamCardoso
18 Sep, 2023, 15:59

I understand. But what is hapening is the body is not even reaching my function. It is going empty

williamCardoso
18 Sep, 2023, 15:59

When I validate the body, it states that it is empty. That's the error. The body is not properly going through curl.

williamCardoso
18 Sep, 2023, 16:24

I fixed. It is the same way as before, but, now it has changed to body

williamCardoso
18 Sep, 2023, 16:25

The Appwrite documentation does not state it anywhere. Very sad. I always get some frustration with such doc. I will try to open pr or issues later to get attention for it

Binyamin
18 Sep, 2023, 16:25
williamCardoso
18 Sep, 2023, 16:26
williamCardoso
18 Sep, 2023, 16:26

thank you very much

williamCardoso
18 Sep, 2023, 16:27

It would be good to also address here some curl example. Idk if my suggestion is not adequate

williamCardoso
18 Sep, 2023, 16:27

[Solved] Empty Body on cURL Request

williamCardoso
18 Sep, 2023, 16:27

I've updated the title to solved

williamCardoso
18 Sep, 2023, 16:31

appwrite rocks!

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