Is it possible to return the underlying reason for a "400 Bad Request" when making an REST API call?

James OBrien asked on May 31, 2017 20:57

I've written C# method to create a user via Kentico REST API call. If the user doesn't currently exist, the REST API call works as expected. If the user already exists, there is no response is empty (null) and receive the following WebException ("The remote server returned an error: (400) Bad Request.")

When I look in the CMS_EventLog table, there is an entry indicating that the user already exists.

Is there any mechanism for retrieving the root cause of a REST API call failure?

Recent Answers


Peter Mogilnitski answered on May 31, 2017 21:14

There is not failure - you get the correct HTTP Response for your request. There a topic on stack overflow on what is the best HTTP response if the object already exists:

400 => "The request could not be understood by the server due to malformed syntax". And the server understands perfectly, but is unable to comply due to a conflict. There is nothing wrong with the request & syntax, only a data problem.

Since POST is "INSERT" operation - 400 is an "appropriate" response in case if an object already exists.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.