Metronome provides programmatic notifications in the form of webhooks. If you configure a webhook URL, Metronome sends an HTTP POST request to that URL when certain events occur, such as a contract being created, a threshold being reached or an invoice being finalized. Your service can then react to that notification by updating customer state, sending an email, or notifying internal users to take some action.
Metronome sends these webhook types:Threshold Notificationsalerts.<notification_type>Threshold notifications monitor real-time metrics and trigger when defined thresholds are crossed. See our threshold notifications documentation for more on how to configure these types of notificationsThreshold notifications have this structure:
System notifications for contract, credit and commit affiliated eventscontract.<notification_type>commit.<notification_type>credit.<notification_type>System notifications monitor when events or actions occur based on the configured timestamp of an object (e.g contract start) or the time at which an action occurred (e.g. contract created). See our system notifications documentation for more on how to configure these types of notificationSystem notifications have this structure:
Offset notifications for contract, credit and commit affiliated eventsOffset notifications allow you to schedule notifications to fire relative to a known date (e.g. a commit’s end date or a contract’s creation date). See our offset notifications documentation for more on how to configure these types of notificationOffset notifications have this structure:
Invoice finalized notificationsinvoice.finalizedTriggered whenever an invoice is finalized (happens after the grace period).Invoice finalized notifications have this structure:
NOTIFICATION CONFIGURATIONTalk to your Metronome representative to set up invoice.finalized notifications.
Billing provider error notifications (Stripe)invoice.billing_provider_errorBilling provider error webhooks only apply to Stripe and are triggered any time there is an error in sending an invoice to Stripe (for example, the customer does not exist within Stripe or the customer does not have a valid payment method). No additional configuration is needed for this webhook; notifications are automatically sent when a webhook destination is set up and the Stripe integration is enabled on the account. Note that no Metronome webhook is triggered for errors residing entirely within Stripe (such as payment failures).Billing provider error notifications have this structure:
{ "id": "c941cccc-a890-45e4-96de-3fdb8a6809f3", "properties": { "invoice_id": "9927e175-c1d3-4f94-875b-8906bc773a95", "customer_id": "83518c41-76ff-4ac4-85d4-bd7010112bd3", "billing_provider": "STRIPE", "billing_provider_error": "No such customer: 'cus_PQzIVPOCGb4otV'" }, "type": "invoice.billing_provider_error"}
Integration Issuesintegration.issueIntegration issue webhooks are triggered when there is an error with the client’s third party integration (for example, invalid credentials, misconfigured connections, or API errors). No additional configuration is needed; notifications are automatically sent when a webhook destination is set up and the integration is enabled.Integration issue notifications have this structure:
AWS marketplace notificationsmarketplaces.aws_metering_disabledTriggered when an AWS marketplace customer is disabledAWS marketplaces metering notifications have this structure:
Azure marketplace notificationsmarketplaces.azure_metering_disabledTriggered when an Azure marketplace customer is disabledAzure marketplaces metering notifications have this structure:
GCP marketplace notificationsmarketplaces.gcp_metering_disabledTriggered when a GCP marketplace customer is disabledGCP marketplaces metering notifications have this structure:
Payment gating notifications are tied to specific workflows in Metronome that gate access to some product (e.g. commit balance) based on successful payment collection.Payment threshold reachedThis webhook is fired when a payment gating action is triggered, such as when a customer hits their threshold_amount for Threshold Billing.Payment gate statusAfter a payment is attempted for a payment gate workflow, this webhook returns the status. It includes relevant metadata from the gateway, such as error codes, if applicable.Payment gate action requiredThis webhook is fired if an additional action is required to complete payment. It includes relevant metadata to identify the associated payment in the gateway, if applicable.External workflow initiated
If processing payment via an external gateway outside of a native Metronome integration, this webhook will provide you the information to process that transaction. The workflow_id provided is used to release or cancel the balance, pending payment outcome.Payment gating notifications have this structure:
Upon receiving a notification, your endpoint must return a successful status code, such as 200 OK. If Metronome receives a status code >299, notification retries are attempted until a successful status code is returned.If your webhook endpoint does not properly acknowledge the notification, Metronome continuously retries it with exponential backoff until it hits a 15-minute retry cadence. Once the retry process hits 15 minutes, Metronome repeats the notification until it is either accepted or two days have passed since the initial notification attempt (~200 retries).It is recommended that you process webhooks asynchronously: store the webhook payload in a queue, return a 200 response code, and only then validate or process the payload. Removing webhook processing from the receiving path reduces the likelihood of your systems getting blocked.
Under normal circumstances, Metronome sends each notification exactly once. However, there are a few situations that could cause you to receive the same notification multiple times:
Retries — As mentioned above, if Metronome receives an error when attempting to deliver the notification to your webhook handler, we retry the notification. Depending on the nature of the error, it’s possible that your endpoint receives a notification without acknowledging it, in which case your endpoint receives the same notification again.
Multiple webhook URLs — If you configure Metronome to notify multiple webhook URLs, or even the same URL multiple times, notifications are sent multiple times. If you want to ensure duplicate notifications are ignored, you can use the notification’s id field to deduplicate.
Because your webhook endpoint is a public URL, anyone could send a request to it. Before you take actions based on the notification, you should verify the information it contains. You can do this in two ways: by fetching data from the Metronome API yourself or by verifying the webhook request’s signature.
INFOMetronome may make introduce backward-compatible changes to existing webhook shapes without notice, such as adding a new webhook field. Metronome recommends that you validate only fields that are expected to be present according to the documentation at time of integration.
Webhook notifications contain only minimal information about the event that occurred. This means it’s often useful to call the appropriate Metronome API endpoint to get the full details. For example, if you receive a webhook notification informing you that an invoice has been finalized, you can call the /customers/{customer_id}/invoices/{invoice_id} endpoint to fetch the details of the invoice mentioned in the notification. In this way, the notification serves as a hint that something has changed, but your code relies only on data obtained directly from the Metronome API.
If the above strategy doesn’t work for your use case, Metronome also provides a method to verify the authenticity of notifications as you receive them by using the Metronome-Webhook-Signature HTTP header. The value of this header is a cryptographic signature of the HTTP request, using a secret key set up when you configure your webhook.
Secret keys are unique per webhookIf you have multiple webhooks configured on your Metronome account, each webhook has its own secret key.
To validate the signature, first concatenate the value of the request’s X-Metronome-Date header and the exact bytes of the request body, separated by a newline character (\n). Then compute the HMAC-SHA256 of the resulting string, keyed by the webhook’s secret key. Finally, compare the hexadecimal representation of the HMAC you computed with the one found in the Metronome-Webhook-Signature header. If they don’t match, the webhook notification did not come from Metronome.
Use X-Metronome-Date instead of DateMetronome sends both an X-Metronome-Date header and a standard Date header with the same value. Prefer X-Metronome-Date for signature verification: it’s preserved end-to-end and isn’t rewritten by intermediaries (load balancers, proxies, or frameworks) that may overwrite the standard Date header, which would otherwise cause signature verification to fail. The Date header is still supported for backward compatibility, but isn’t recommended.
The X-Metronome-Date header is included to aid in deduplication. You should ignore webhook requests that are older than five minutes, which means your webhook handler only needs to store recent notification IDs to prevent duplicates.
THE BODY MUST BE TREATED AS BYTESWhen computing the signature, Metronome uses the exact bytes sent in the request body. Be careful to do the same in your code. If you try to use the parsed JSON body for verification purposes, you’ll likely fail signature verification because serializing the data again is not guaranteed to produce the same JSON.
The following code example shows how to perform signature validation:
If you want to receive Metronome notifications in Slack without building a custom webhook handler, you can configure Metronome to send notifications directly to a Slack channel. From there, you can triage and act on them. To send Metronome webhooks to Slack:To send Metronome webhooks to Slack:
Create an incoming webhook in Slack and copy the generated webhook URL. It’ll look something like: https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
Create a webhook destination in Metronome for your Slack channel. In the Metronome app, go to Connections > API tokens & webhooks > Webhooks > Add and paste your Slack webhook URL.
Set up a test notification to verify the integration. In the Metronome app, go to Connections > Notifications > Create Notification and create a notification like Low credit balance reached.
Verify the integration by testing the webhook connection. Trigger your test notification and check your Slack channel for a message from Metronome.
When properly configured, you’ll receive Slack messages that look like this: