Cannot set API header for Content-Type

Please help. I’ve been spending the last hour on this seemingly trivial issue.
Screenshot 2023-06-11 at 00.16.11
I am trying to set my API header to “Content-Type: application/json”. I have done it before and it was working, but when trying it now, my headers don’t get the Content-Type parameter. I’ve been printing it to debug, and it is just not part of the headers obtained on the server. Am i doing anything wrong, or is there a bug?

Your header blocks are correct.

Thank you.
And yet when I run a curl request in my terminal: curl -X POST -H “Content-Type: application/json” -d … I get a good response, but when I use Thunkable as I showed above I keep getting “415 Unsupported Media Type: Did not attempt to load JSON data because the request Content-Type was not ‘application/json’.” In order to debug was printing all the headers obtained by the request, and indeed it does not get my headers on Thunkable.

The headers aren’t really going to be displayed since they are an object. If you set the headers (temporarily) to a text string, you should see them when you debug the code. But as an object, the best you’re going to get is “[object]”.

I’m guessing there’s something else wrong with your blocks but you’ve hidden them either outside of the screenshot or with black pen so it’s not possible for me to know.

Hi, sorry I cannot provide much more data, but let me describe it in more detail: I deployed python code on a server (Google Cloud Functions) to intercept the request and I printed the headers there, not on Thunkable. The problem is when I call it with curl everything works perfectly, and I can even print the headers with: print(request.headers.get(‘Content-Type’)) and the body with print('Data: ', request.data). However, when I call it using Thunkable it seems that it cannot somehow parse my headers or the body parameters I guess, so it still prints the headers but w/o any Content-Type (which later produces the error I showed above), and also the data is not parsed correctly as I am getting an empty strong on the server. Yet, the function on my server is being triggered, so it triggers the correct HTTP url.

OK, I was reading few old posts about flask deployment, and I could see that other users had bugs when testing on the web version of Thunkable (here for example: [Solved] how can I fix a 403 error using the WEB API - #9 by muneer). So, I moved to test on my mobile (Android Samsung, but in the post I referenced they also report that it worked on Iphone), and surprisingly - it worked great when I tested on Thunkable mobile app. So, in conclusion, seems like there is a problem when testing/calling API requests as web app. For now, I will call it solved, although I would appreciate if you could help us find a solution to test it also on the web.

1 Like

I don’t work for Thunkable so I won’t be the one to find a solution but perhaps the Thunkable Staff will be able to. I know that many API calls don’t work in a web browser and instead must be run on a mobile device, as you mentioned.

CORS policy is one cause of this: What is the CORS policy affecting my web app? | Thunkable Help Center

3 Likes

You are describing a CORS issue. It’s not a Thunkable thing, it’s your server. You’ll experience the same thing on bubble and even weweb

Thank you guys!