githubEdit

Webhooks

Guide explains how to manage webhooks using Supervisely SDK and API

Introduction

In this tutorial you will learn how to manage Webhooks using Supervisely SDK and API. Webhooks allow you to receive real-time notifications when certain events occur in your team, such as labeling job completion or labeling queue updates.

Webhooks automation

Import libraries

import os
from dotenv import load_dotenv
import supervisely as sly

Init API client

Init API for communicating with Supervisely Instance. First, we load environment variables with credentials:

if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api.from_env()

Get your Team ID from environment

team_id = 123  # change to your team ID

Available webhook actions

Supervisely supports the following webhook action types:

  • sly.LABELING_JOB_COMPLETED - Triggered when a labeling job is completed

  • sly.LABELING_QUEUE_JOB_COMPLETED - Triggered when a job in labeling queue is completed

  • sly.LABELING_QUEUE_COMPLETED - Triggered when entire labeling queue is completed

Create a webhook

Create a new webhook that will be triggered when a labeling job is completed:

Create webhook with custom headers

You can add custom headers to your webhook requests, for example for authentication:

Parameters explanation

  • team_id - ID of your team where the webhook will be active

  • url - Target URL that will receive webhook POST requests

  • action - Type of event that triggers the webhook (use constants from sly)

  • retries_count - Number of retry attempts if webhook delivery fails (default: 5)

  • retries_delay - Delay in seconds between retry attempts (default: 10)

  • headers - Dictionary of custom HTTP headers to include in webhook requests

  • follow_redirect - Whether to follow HTTP redirects (default: True)

  • reject_unauthorized - Whether to reject unauthorized SSL certificates (default: True)

Get list of webhooks

Get all webhooks in your team:

Filter webhooks

You can filter webhooks by specific criteria:

Get webhook information by ID

Retrieve detailed information about a specific webhook:

Update a webhook

Update an existing webhook's properties:

Note: Only the parameters you specify will be updated. Other parameters will remain unchanged.

Test a webhook

Send a test event to verify your webhook is working correctly:

Test webhook with custom payload

You can also test a webhook with a custom payload:

Remove a webhook

Delete a webhook when it's no longer needed:

Webhook payload structure

When a webhook is triggered, Supervisely sends a POST request to your URL with the following structure:

Labeling Job Completed Event

Labeling Queue Job Completed Event

Labeling Queue Completed Event

Complete example

Here's a complete example that demonstrates webhook management:

Best practices

  1. Use HTTPS endpoints - Always use secure HTTPS URLs for your webhook endpoints

  2. Validate webhook signatures - Implement signature validation on your server to ensure requests are from Supervisely

  3. Handle retries gracefully - Make your endpoint idempotent to handle potential duplicate deliveries

  4. Set appropriate retry settings - Configure retries_count and retries_delay based on your endpoint's reliability

  5. Monitor webhook health - Regularly check webhook delivery status and update if needed

  6. Use custom headers for authentication - Add authentication tokens in headers rather than in URL parameters

  7. Test before production - Use the test() method to verify your webhook endpoint works correctly

Troubleshooting

Webhook not receiving events

  1. Verify the webhook URL is publicly accessible

  2. Check that the action type matches the events you expect

  3. Ensure your server accepts POST requests

  4. Check server logs for incoming requests

SSL/TLS errors

If you're getting SSL errors, you can temporarily disable certificate validation:

Warning: Never use reject_unauthorized=False in production environments.

Last updated