See Webhooks Guide page for details on how you can use Webhooks to receive notifications from activities in Labelbox.

Configure server to receive requests

# This can be any secret that matches your webhook config (we will set later)
secret = b"CHANGE-ME" 

# Example for server-side code to receive webhook events
app = Flask(__name__)

@app.route("/webhook-endpoint", methods=["POST"])
def print_webhook_info():
    payload = request.data
    computed_signature = hmac.new(secret, msg=payload,
                                  digestmod=hashlib.sha1).hexdigest()
    if request.headers["X-Hub-Signature"] != "sha1=" + computed_signature:
        print(
            "Error: computed_signature does not match signature provided in the headers"
        )
        return "Error", 500, 200

    print("=========== New Webhook Delivery ============")
    print("Delivery ID: %s" % request.headers["X-Labelbox-Id"])
    print("Event: %s" % request.headers["X-Labelbox-Event"])
    print("Payload: %s" %
          json.dumps(json.loads(payload.decode("utf8")), indent=4))
    return "Success"


thread = threading.Thread(target=lambda: run_simple("0.0.0.0", 3001, app))
thread.start()

Create webhook

from labelbox import Client, Webhook

public_url = "https://example.com/webhook-endpoint" # Your server's public url - where the messages will be sent to 
secret = b"CHANGE-ME" # Use to verify Labelbox is sending the message

client = Client(api_key="<YOUR_API_KEY>")
project = client.get_project("<project_id>") 
print([topic.value for topic in Webhook.Topic]) # See all available topics 
secret = b"example_secret" # This can be any secret that matches your webhook config (we will set later)

webhook = Webhook.create(client,
                         topics=["LABEL_CREATED"],
                         url="public_url",
                         secret=secret.decode(),
                         project=project)

Get webhooks

# Fetch all webhooks
org = client.get_organization()
webhooks = org.webhooks() #paginated 

# Fetch project webhooks
project = client.get_project("<project_id>")
webhooks = project.webhooks()  #paginated 

webhook = next(webhooks)
status = webhook.status
server_url = webhook.url
topics = webhook.topics
project = webhook.project()

Update webhook

# url, topics, and status can all be updated
updated_url = f"{public_url}/webhook-endpoint"
webhook.update(url=updated_url, topics=[Topic.LABEL_DELTED], status=Webhook.Status.INACTIVE.value)

Delete webhook

webhook.delete()