FANDOM


Habitica provides "webhooks" for certain actions that can occur in your account (for example, when you complete a task or when someone posts a message in a Guild that you belong to). A webhook will be triggered when such actions occur and it will send information about the action to a script or other tool on another website.

You can specify which scripts should receive information from Habitica's webhooks by logging in to Habitica's website and going to User Icon > Settings > API.

Specifying an incorrect URL can cause errors or slowness in Habitica so it's best to not use this feature if you are unsure how webhooks work.

More information is available in the Webhooks section of Habitica's API Documentation. If you need help with developing a script that responds to a webhook, ask for advice from other developers in the Aspiring Comrades guild.

If you wish to gain recognition for your webhook development, please see Guidance for Comrades for more information.

ExamplesEdit

Python Flask ExampleEdit

The following script uses Python Flask to implement handling for webhooks. The URL that you enter into Habitica's website should look like: http://<your_ip>:<your_port>/taskevent

Flask listens on port 5000 by default, but you can specify a different port where indicated by <your_port>

If your script is hosted behind a firewall you may need to use port forwarding or allow access to the port through the firewall.

from flask import Flask, request
app = Flask(__name__)
  # URI for receiving inbound webhook request
@app.route('/taskevent', methods=['POST'])
def webhook():
    # Request contains data as shown at https://habitica.com/apidoc/#api-Webhook
     # .json converts request to Python dictionary
    print(request.json)  # type: dict
 
    # <YOUR CODE FOR HANDLING EVENT HERE>
 
    return '', 200 # Return 200 code to the sending webserver
 
if __name__ == "__main__":
    app.run(host='0.0.0.0', port='<your_port>')
Community content is available under CC-BY-SA unless otherwise noted.