[Resolved] Why does webhooks get suspended (.net Webapi) and request received 3 times.
Hi, I found the solution to my problem but figured it might be helpful to others.
Platform
.Net ( webapi /MVC) project
Issue
Webhooks keep getting suspended and request are sent 3 times.
Investigation results
By default, the POST action sent to the web api will respond with a 204 (no content) status code.
It is not mentionned at this time in the documentation (It should be) but Response must be 200 Ok status code.
Otherwise, the webhook is called a second and third time before being suspended.
Solution
By changing the default void method for a function which return a Ok Status code, you can change the default 204 status code message generated by .net webapi to a 200 response.
Before
Public sub PostValue(<FromBody()> ByVal value As Object)
' My code
End sub
After
Public Function PostValue(<FromBody()> ByVal value As Object) As HttpResponseMessage
Return Request.CreateResponse(HttpStatusCode.OK)
End Function
I lost a few hours figuring that out so I am putting it out there hoping to save some time to others.
(It would also be a good addition in the official documentation to mention the proper status code response and the 3 attempts behaviors.)
Francis, thank you for your post and congrats on being the first contributor to our API community!
This is a great tip, I am sure many API users will find it useful. Your feedback came just in time! We plan on updating the documentation on webhooks soon, and we agree that these points should be reflected in our help docs.
Our engineers may also consider accepting the 204 status code and at this point it would be great to hear your thoughts about it: what is your personal opinion on the necessity of this? We assume that your .Net library defaults to 204, do you feel like accepting only the 200 code would be a serious limitation?
Thank you.
A serious limitation (or even a limitation), definitely not.
By default, 204 response means the server has fulfilled the request but does not need to return an entity-body.
Since payload sent does not except a body returned to it and also that Microsoft developped their .net webapi POST handle to use that response as default behavior, I would be inclined to think that it could be good to accept by default 204 response too.
(Please note that "my .net library" was actually Microsoft sample project with nothing custom at all. I did not choose the 204 response for the post request myself, their implementation defines it as the default response for Post request)
However, that being said and even though I could not find any evidence to not use it as a valid response, I do not see any problem complying to the 200 status response needed at this time.
Thank you for your feedback, Francis! This definitely makes sense, we will discuss the possibilities of avoiding such limitations in the future.
Francis, we have great news - our engineers have released the update to Webhooks, which allows Wrike's API to accept the 204 status code.
Anyways, I wanted to thank you again for your workaround and contribution to the Community. What you proposed was an easy and elegant way to avoid the limitation!