Webhooks

Description

The Miri SDK includes web hook events that support real-time data updates, event tracking, and actionable alerts in your application. This feature provides developers with the flexibility to receive updates from Miri’s API and respond to various user actions or events, such as logging a meal, achieving goals, or making updates to a user profile.

Events

Web hooks are a mechanism by which Miri can send real-time HTTP POST requests to a specified URL endpoint in your server when certain events occur within the Miri platform. This enables your application to stay synchronized with Miri’s system updates or specific user actions.

Events that can trigger a webhook:

  • Meal Log Updates: Triggered when a user logs or updates their meal information, enabling real-time data sync and support for customized nutritional analysis.
  • Goal Completion: Triggered when a user completes a fitness or wellness goal, allowing you to reward users or trigger follow-up actions in your app.
  • User Profile Updates: Triggered when a user updates their profile, such as adding a new fitness goal or updating personal information.
  • Coach Interaction: Triggered whenever a user interacts with the Miri AI Coach, such as sending or receiving messages.
  • Push Notifications: Triggered when Miri would like to send a notification to the user

Configuring Webhooks

To integrate web hooks in your application, follow these steps:

  1. Define Your Endpoint: Choose or set up an endpoint on your server that Miri can send web hook requests to. Ensure that this endpoint is configured to accept HTTP POST requests.
  2. Configure Web Hooks in Miri: In your Miri developer account, navigate to the "Web Hooks" section and add your endpoint URL. Select the events you want to listen to and configure any necessary authorization headers for secure communication.
  3. Secure Your Web Hooks: Web hooks are authenticated through API keys or tokens, depending on your security needs. Ensure your endpoint verifies the source of each request using the headers or tokens provided by Miri, and validate the payload to prevent unauthorized access.
  4. Handle Events: When an event triggers a web hook, Miri will send a POST request to your endpoint with a JSON payload containing details about the event. Your server should parse the payload and respond with a 200 status code to acknowledge receipt.

Sample Webhook Payload

Here's an example payload for a goal completion event:

{
"event": "goal_completed",
"occurred_at": "2024-11-11T10:35:00Z",
"user_id": "USER12345",
"goal_artifact_id": "GOAL56789",
"goal_name": "Lose weight",
"data": {
"completed_at": "2024-11-10T14:30:00Z",
"weight_goal": {
"value": 15,
"unit": "pounds"
}
}
}

Error Handling

Web hooks are resilient to temporary issues, but they require consistent responses to avoid repeated failed attempts. If your endpoint does not respond with a 200 status, Miri will attempt to resend the request based on a back-off policy.