I am writing an API for a financial vendor I use. Their API includes webhooks which I have been able to receive but I’m not sure how to satisfy the required acknowledgement. In the HandleSpecialURL handler, I need to acknowledge that I successfully received the webhook.
Their documentation states…
[quote]Responding to a webhook
To acknowledge that you received the webhook without any problem, your server should return a 200 HTTP status code. Any other information you return in the request headers or request body will be ignored.[/quote]
I’m guessing that a simple Request.Print ("200 OK" + EndOfLine)
isn’t going to do the trick. So how would I return a “200 HTTP status code?”
I can’t speak directly for the web edition, because I’ve not used it, but I implemented some web hook stuff on our website last week, and didn’t have to do anything special. So, the entire code in the page was something like this:
[code]
// Process the variables posted here, put them into a database, etc. etc.
</php[/code]
ie no special returning of anything. Because the server returns statuses itself (and that status is 200 OK if the page was successfully served) then I don’t need to do anything. I’m presuming it would be similar for the web edition.
(Note: “The default value is 200”. So, my assumption was correct: you don’t need to do anything special, assuming you don’t have any server errors which give 400 codes.)
Yes but with special URL handlers I would always err on the side of specifically setting the status code to be what you want it to be rather than Xojo using defaults, this way you ensure you are totally in control of what is being sent back. I know this is probably a bit pedantic but I prefer to do this.
To each their own; I prefer letting the server do it, in case some kind of misconfiguration means I can’t connect to the database, and my script bombs out, or something similar - I don’t want to have to remember to serve something different then. Most places which provide web hooks will look at the status returned and if it’s anything other than 200 will keep trying every hour for a few days, or something similar. I guess either way is valid!
Set WebRequest.Status and return True from the HandleSpecialUrl event.
I tend to have a property which contains a boolean which I default to false and another property I store the status which I default to 503. Whenever I do a return status I update the properties and always return them values from those properties. This way I am always failing in error state unless specifically setting the state / status to be good. This way the web hooks will not get a 200 back unless I have specifically told the code to return it so the web hooks will either retry or fail which is correct unless the code has functioned correctly.
Greg - I have the following code in the HandleSpecialUrl event but the webhook continues to be received since the API doesn’t receive the 200 status back. Is there something else I need to do?
Request.Status = 200
Return True
[quote=103367:@Scott Rich]Greg - I have the following code in the HandleSpecialUrl event but the webhook continues to be received since the API doesn’t receive the 200 status back. Is there something else I need to do?
Request.Status = 200
Return True
[/quote]
I suggest writing something. The API says that it’ll be ignored, but I’d suggest you at least send an empty string like:
Request.Print ""
The web framework expects that you are writing something if you are returning true.
It seems to be working. Thank you.