Before you can register webhooks for specific shops, you must add the desired topics to the local ShopifyAPI::Webhooks::Registry. This should be done once during app startup (e.g., when setting up ShopifyAPI::Context).
Use ShopifyAPI::Webhooks::Registry.add_registration with the following parameters:
topic (String): The webhook topic (e.g., "orders/create").delivery_method (Symbol): The method of delivery. Supported values: :http, :event_bridge, :pub_sub.handler (Class/Module): The handler implementation (required for :http).path (String): The relative path for HTTP webhooks, or an ARN/PubSub URI for other methods.fields (Array of Strings or comma-separated String, optional): Filters the payload to specific fields.metafieldNamespaces (Array of Strings, optional): Ensures specific metafield namespaces are included in the payload. If using fields, you must also include "metafields" in the fields list.filter (String, optional): A webhooks filter string.
Note: The local registry must be reloaded whenever your server restarts, even though the registrations are saved on the Shopify platform.
# Basic HTTP registration
ShopifyAPI::Webhooks::Registry.add_registration(
topic: "orders/create",
delivery_method: :http,
handler: WebhookHandler,
path: 'callback/orders/create'
)
# Registration with field filtering
ShopifyAPI::Webhooks::Registry.add_registration(
topic: "orders/create",
delivery_method: :http,
handler: WebhookHandler,
path: 'callback/orders/create',
fields: ["number", "note"]
)
# Registration with metafield namespaces
ShopifyAPI::Webhooks::Registry.add_registration(
topic: "orders/create",
delivery_method: :http,
handler: WebhookHandler,
metafieldNamespaces: ["custom"]
)
# Registration with a filter
ShopifyAPI::Webhooks::Registry.add_registration(
topic: "products/update",
delivery_method: :http,
handler: WebhookHandler,
filter: "variants.price:>=10.00"
)