This blog post explains potential causes of HTTP 400, 401, 412, 422, and 429 errors when using the Contentstack SaaS headless CMS.
When you cannot access details about an error, the HTTP status code can suggest a solution. Today I received HTTP 412 when calling Contentstack content management services from .NET. All I could see was HTTP 412 Precondition failed. I could not recreate the issue in Postman until I speculated about possible causes, where postman rendered a more helpful message from Contentstack.
As it turned out, I had removed two critical HTTP request headers: api_key, which identifies the stack, and authorization, which grants access to a stack.
Placing the request without api_key or with an invalid api_key results in HTTP error 412, Precondition failed.
Passing a valid api_key without authorization or with invalid authorization results in HTTP error 401, Unauthorized.
Placing a request with an invalid Content-type results in HTTP error 400, Bad request. In general, use application/json. HTTP 400 can also mean malformed JSON in your request. See the note about 422 in the Contentstack documentation that lists more general possible causes of errors:
This reminds me that I have seen 422 Unprocessable entity (the syntax of the request is valid but there is a semantic error) and I think 429 Rate limit exceeded (too many API calls per CMS rate plan). Update 2.April.2021: I just received 422 trying to set a field to a value that did not match the validation regular expression for the field.
If you know of other causes for these or other errors while using Contentstack, please comment on this blog post.