Webhooks in SDK

Create and manage notification events using the SDK.


Overview

A webhook is a method for sending event notifications from one application to another. When something happens in a source system indicated by an event, the webhook transmits an event notification through HTTPS to a specific URL.

You can set up webhooks to receive notifications for order status updates.

View repository

Class: Webhook

A data class that represents a webhook in the system.

Attributes

AttributeDescription
urlstr
The URL of the webhook.
namestr
The name of the webhook.
eventsList[str]
A list of events that trigger the webhook. To view the list of possible values, use get_webhook_events.
activebool
Whether this webhook should be active after the update:
  • True: The webhook is active.
  • False: The webhook isn’t active.
The default value is False.
secretOptional[str]
The secret used to generate webhook signatures.
idOptional[str]
The webhook ID.
created_atOptional[str]
The timestamp when the webhook was created.
updated_atOptional[str]
The timestamp when the webhook was last updated.
Python
# Select a webhook
webhook_id = "d290f1ee-6c54-4b01-90e6-d701748f0851"
# Fetch webhook info
webhook = up42.Webhook.get(webhook_id=webhook_id)
# Define output
print(f"ID: {webhook.id}")
print(f"Name: {webhook.name}")
print(f"URL: {webhook.url}")
print(f"Active: {webhook.active}")
print(f"Events: {webhook.events}")
print(f"Created at: {webhook.created_at}")
print(f"Updated at: {webhook.updated_at}")

Methods

save

Registers a created or updated webhook in the system.

Python
# Instantiate a new webhook
webhook = up42.Webhook(
name="My order status Webhook",
url="https://example.com/my-webhook-callback",
events=["order.status"],
active=True,
secret="secret-to-validate-payloads"
)
# Save the webhook
webhook.save()
# The object is updated with the server response
print("\nWebhook created successfully:")
print(f"ID: {webhook.id}")
print(f"Name: {webhook.name}")
print(f"URL: {webhook.url}")
print(f"Active: {webhook.active}")
print(f"Created at: {webhook.created_at}")
Python
# Select an existing webhook that you want to update
webhook_id = "d290f1ee-6c54-4b01-90e6-d701748f0851"
# Fetch webhook info
webhook = up42.Webhook.get(webhook_id=webhook_id)
# Modify its attributes
webhook.name = "Test webhook"
webhook.url = "https://example.com/my-webhook-callback"
webhook.events=["order.status"]
webhook.active = False
webhook.secret="secret-to-validate-payloads"
# Save the webhook
webhook.save()
# The object is updated with the server response
print("\nWebhook updated successfully:")
print(f"Updated at: {webhook.updated_at}")

get

Retrieves a specific webhook by its ID. Returns Webhook.

ParameterDescription
webhook_idstr
The webhook ID.
Python
# Select a webhook
webhook_id = "d290f1ee-6c54-4b01-90e6-d701748f0851"
# Fetch webhook info
webhook = up42.Webhook.get(webhook_id=webhook_id)

trigger_test_events

Triggers a webhook test event to test your receiving side. The UP42 server will send test messages for each subscribed event to the specified webhook URL. Returns dict.

Python
# Select a webhook
webhook_id = "d290f1ee-6c54-4b01-90e6-d701748f0851"
# Fetch webhook info
webhook = up42.Webhook.get(webhook_id=webhook_id)
# Trigger the test events
test_event_info = webhook.trigger_test_events()
# Define output
print(test_event_info)

delete

Deletes a registered webhook. Returns None.

Python
# Select a webhook
webhook_id = "d290f1ee-6c54-4b01-90e6-d701748f0851"
# Fetch webhook info
webhook = up42.Webhook.get(webhook_id=webhook_id)
# Delete the webhook
webhook.delete()

get_webhook_events

Retrieves all available webhook events. Returns list[dict].

Python
# Search for event types
events = up42.Webhook.get_webhook_events()
# Define output
for event in events:
print(f"- Name: {event['name']}")
print(f" Description: {event['description']}\n")

all

Retrieves all webhooks in your workspace. Returns List["Webhook"].

Python
# Search for webhooks
webhooks = up42.Webhook.all()
# Define output
for webhook in webhooks:
print(f"- ID: {webhook.id}")
print(f" Name: {webhook.name}")
print(f" URL: {webhook.url}")
print(f" Active: {webhook.active}")
print(f" Events: {', '.join(webhook.events)}\n")

Learn more


Last updated: