Webhooks Advanced Usage

Pro Feature

Webhook support is available exclusively for Reasoner Pro users.

Complete Code Examples

These examples show production-ready implementations with proper error handling and security practices.

1import requests
2import base64
3import json
4import os
5
6# Get credentials from environment variables for security
7username = os.environ.get("REASONER_WEBHOOK_USERNAME")
8password = os.environ.get("REASONER_WEBHOOK_PASSWORD")
9
10if not username or not password:
11 raise ValueError("Missing webhook credentials. Set REASONER_WEBHOOK_USERNAME and REASONER_WEBHOOK_PASSWORD environment variables.")
12
13# Create the authorization header
14credentials = f"{username}:{password}"
15encoded_credentials = base64.b64encode(credentials.encode()).decode()
16auth_header = f"Basic {encoded_credentials}"
17
18# Prepare your data
19payload = {
20 "event": "data_update",
21 "timestamp": "2023-06-15T14:22:10Z",
22 "data": {
23 "key1": "value1",
24 "key2": "value2"
25 }
26}
27
28# Send the request
29response = requests.post(
30 "https://webhook.reasoner.com",
31 headers={
32 "Content-Type": "application/json",
33 "Authorization": auth_header
34 },
35 json=payload # This automatically serializes the dict to JSON
36)
37
38# Handle the response
39if response.status_code == 200:
40 print("Success! Data sent to Reasoner.")
41 print(f"Response: {response.text}")
42else:
43 print(f"Error: {response.status_code}")
44 print(f"Response: {response.text}")

Best Practices

  • Store credentials in environment variables or a secure vault, never in code
  • Rotate credentials periodically
  • Use different credentials for different environments (development, staging, production)
  • Use consistent JSON structures for your webhook payloads
  • Include metadata like timestamps and event types
  • Keep payloads concise and relevant

Example structure:

1{
2 "event": "user_action",
3 "timestamp": "2023-06-15T14:22:10Z",
4 "source": "web_app",
5 "data": {
6 // Your specific data here
7 }
8}
  • Implement retry logic with exponential backoff for failed requests
  • Log detailed error information for troubleshooting
  • Set up monitoring to alert on persistent failures

Python example with retries:

1import requests
2from requests.adapters import HTTPAdapter
3from urllib3.util.retry import Retry
4
5# Configure retry strategy
6retry_strategy = Retry(
7 total=3,
8 backoff_factor=1,
9 status_forcelist=[429, 500, 502, 503, 504],
10)
11
12# Create a session with the retry strategy
13session = requests.Session()
14session.mount("https://", HTTPAdapter(max_retries=retry_strategy))
15
16# Use session for requests
17response = session.post(
18 "https://webhook.reasoner.com",
19 headers=headers,
20 json=payload
21)
  • Avoid sending too many requests in a short period
  • Batch data when possible instead of sending many small payloads
  • Implement queuing for high-volume scenarios

Troubleshooting

Common Issues and Solutions

If you encounter problems with your webhook implementation, check these common issues:

Authentication Errors (401 Unauthorized)

1

Verify your credentials are correct and up to date

2

Check that your Base64 encoding is correct (no newlines or extra characters)

3

Ensure the Authorization header format is exactly: Basic <base64-encoded-credentials>

4

Try regenerating your webhook credentials in Reasoner Settings > Integrations

Request Format Issues (400 Bad Request)

1

Confirm your Content-Type header is set to application/json

2

Validate that your JSON payload is properly formatted (use a JSON validator)

3

Check for special characters or encoding issues in your payload

Connection Problems

1

Verify your network connection and internet access

2

Check if there are any firewall rules blocking outbound connections to webhook.reasoner.com

3

Ensure you’re using HTTPS (not HTTP) for the webhook URL

4

Try the request from a different network to rule out local network issues

Need More Help?

If you’re still experiencing issues after trying these solutions, contact Reasoner support with:

  • The exact request you’re trying to send (with sensitive data redacted)
  • Any error messages or status codes you’re receiving
  • Your environment details (programming language, library versions, etc.)

FAQ

The webhook endpoint accepts JSON data only. Make sure your Content-Type header is set to application/json and your payload is valid JSON.

Yes, webhook payloads are limited to 10MB. For larger datasets, consider breaking them into smaller chunks or using a different data ingestion method.

A successful webhook request will receive a 200 OK response. You can also check your Reasoner dashboard for the received data.

Yes, webhooks work well with serverless functions like AWS Lambda, Google Cloud Functions, or Azure Functions. Just make sure to securely store your credentials using the environment’s secret management system.

Go to Settings > Integrations in your Reasoner dashboard and generate new webhook credentials. Make sure to update all your systems using the old credentials before deactivating them.