Back

[SOLVED] Function Headers in Cloud Console Is Broken

  • 0
  • Functions
  • Cloud
itsjustintime
30 Dec, 2023, 23:06

When I execute a NodeJS function via the Cloud console, I get this request header: "content-type":"application/x-www-form-urlencoded"

This breaks things since my code is expecting a JSON payload.

So I manually set the content type to application/json with the Headers field shown in the screenshot. When this runs, it fails in 1-3 ms and there are no errors whatsoever to troubleshoot (see screenshot).

I've tried variations of this input such as "Content-Type" content-type Content-Type "application/json" ... etc. Doesn't work.

I then tried using a cURL command to hit the endpoint directly with the headers set and it works without any issues.

This leads me to believe that the Cloud Console's Headers field isn't working properly.

TL;DR
The user was experiencing issues with the function headers in the Cloud Console. It seemed to be working intermittently and there was confusion regarding the behavior when executed via the console versus calling the function directly. The user provided a workaround using curl to set the headers manually and mentioned plans to introduce custom headers in the future. The user also shared a NodeJS function header that was causing issues, and others suggested possible solutions such as parsing the request body and checking the network logs for the request payload. The user concluded that the Headers field in the Cloud Console was not working properly.
Guille
30 Dec, 2023, 23:25

You can try

TypeScript
const body = JSON.parse(req.bodyRaw)
itsjustintime
30 Dec, 2023, 23:26

Thanks! I'm aware of this workaround. I plan on introducing custom headers in the near future so this extends beyond just being able to define the content type.

Drake
30 Dec, 2023, 23:32

Can you check the network logs for the request from the Console and check the payload?

What was the curl you executed?

itsjustintime
30 Dec, 2023, 23:44

This is odd. It seems to be working now. I ran a few with UI. I guess I'll open another issue if I see it again. But for your reference, I was using

TypeScript
curl -X POST <endpoint>.appwrite.global/feedback \
     -H "Content-Type: application/json" \
     -d '{"name": "panda", "email": "fake@placeholder.com", "message": "ur awesome", "userId": "12345"}'
Drake
30 Dec, 2023, 23:45

Fyi, when executed via the console, the create execution API is called and it's executed asynchronously. This behaves slightly differently than calling the function domain

itsjustintime
30 Dec, 2023, 23:46

[SOLVED] Function Headers in Cloud Console Is Broken

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