400 Bad request

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

I try to test GET and POST request on FlexSearch Server which eventually I have to create a search index on my web portal.
So I want to see if the server’s response both POST and GET,however,I get “400 Bad request” error every time.Moreover the error point out that “The request cannot be fulfilled due to bad syntax”.

The GET and POST requests are below:

The GET:

http://localhost:9800/indices/contact HTTP/1.1

THE POST

http://localhost:9800/indices HTTP/1.1

and body for the post:

Content-Type: application/json; charset=utf-8

{
  "indexName": "contact",
  "fields": [
    {
      "fieldName": "employeeid",
      "fieldType": "Keyword",
    },
    {
      "fieldName": "firstname"
    },
    {
      "fieldName": "lastname",
    },
    {
      "fieldName": "dob",
      "fieldType": "DateTime",
    }
  ]
}

Where do I make a mistake?
I would be appreciated to your response.

@joshuacos1977 Warm welcome to this Community :slightly_smiling_face:

Just by quick eye-balling I see that JSON format is incorrect. Removed the trailing commas to fieldType.

{
   "indexName":"contact",
   "fields":[
      {
         "fieldName":"employeeid",
         "fieldType":"Keyword"
      },
      {
         "fieldName":"firstname"
      },
      {
         "fieldName":"lastname"
      },
      {
         "fieldName":"dob",
         "fieldType":"DateTime"
      }
   ]
}

Can you please try with this JSON?

Usually bad request happens when there is some error is your body which couldn’t be handled by your API, or some syntax error in the body :slightly_smiling_face:

I am still getting the same error.
Should I put “Content-Type: application/json; charset=utf-8” on my body or address?

is my request correct format ?I mean
http://localhost:9800/indices HTTP/1.1

@joshuacos1977 Your content type should be as part of Headers section like below:

Also how are you passing the body section? As RAW JSON? Like this?

Can you please provide me more details/screenshots to say exactly what’s not working :slight_smile:?

What is the message being returned? 400 typically means you passed something invalid to the API. These error messages tend to be pretty helpful when it comes to figuring out what is wrong.

The 400 (Bad Request) status code indicates that the server cannot or will not process the request because the received syntax is invalid, nonsensical, or exceeds some limitation on what the server is willing to process. It means that the request itself has somehow incorrect or corrupted and the server couldn’t understand it. The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method . Therefore, it prevents the website from being properly displayed. The main thing to understand is that the 400 Bad Request error is a client-side error. The cause of a 400 error can be a wrongly written URL or a URL that contains unrecognizable characters. Another cause of the error might be an invalid or expired cookie. Also, if you try to upload a file that’s too large. If the server is programmed with a file size limit, then you might encounter a 400 error.

Have the same issue with the client (windows). Same profiles are working from Postman online without any problems. When using the windows client, Postman respond is “HTTP Error 400. The request hostname is invalid.”

<HEAD>
	<TITLE>Bad Request</TITLE>
	<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii">
</HEAD>

<BODY>
	<h2>Bad Request - Invalid Hostname</h2>
	<hr>
	<p>HTTP Error 400. The request hostname is invalid.</p>
</BODY>

</HTML>