8

Suppose that I've an API that publishes a post in my Facebook account. What HTTP code should I return if the user hasn't linked yet his FB account with my API server (it's just an example)? I found "412 Precondition Failed" but I think that this is not the right use case. So what is the best HTTP code for telling that you should do an action first?

EDIT: just to help who will read this post; I've found a nice article that helps to choose the right HTTP status code. https://www.loggly.com/blog/http-status-code-diagram/

1 Answers1

6

The response code "409 Conflict" appears to be the best matching code. The description states

The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough information for the user to recognize the source of the conflict.

The response should tell the user that they need to link a Facebook account to resolve the conflict state and be able to successfully re-submit the request.