pub struct WebhookRegistrationBuilder { /* private fields */ }Expand description
Builder for constructing WebhookRegistration instances.
This builder provides a fluent API for configuring webhook registrations.
Required fields (topic and delivery_method) are set via the constructor, while
optional fields can be set using method chaining.
§Example
use shopify_sdk::webhooks::{WebhookRegistrationBuilder, WebhookDeliveryMethod};
use shopify_sdk::rest::resources::v2025_10::common::WebhookTopic;
let registration = WebhookRegistrationBuilder::new(
WebhookTopic::ProductsUpdate,
WebhookDeliveryMethod::Http {
uri: "https://example.com/api/webhooks/products".to_string(),
},
)
.include_fields(vec!["id".to_string(), "title".to_string()])
.metafield_namespaces(vec!["custom".to_string()])
.filter("vendor:MyVendor".to_string())
.build();
assert!(registration.include_fields.is_some());
assert!(registration.filter.is_some());Implementations§
Source§impl WebhookRegistrationBuilder
impl WebhookRegistrationBuilder
Sourcepub fn new(topic: WebhookTopic, delivery_method: WebhookDeliveryMethod) -> Self
pub fn new(topic: WebhookTopic, delivery_method: WebhookDeliveryMethod) -> Self
Creates a new builder with the required fields.
§Arguments
topic- The webhook topic to subscribe todelivery_method- The delivery method for the webhook
§Example
use shopify_sdk::webhooks::{WebhookRegistrationBuilder, WebhookDeliveryMethod};
use shopify_sdk::rest::resources::v2025_10::common::WebhookTopic;
let builder = WebhookRegistrationBuilder::new(
WebhookTopic::OrdersCreate,
WebhookDeliveryMethod::Http {
uri: "https://example.com/webhooks/orders".to_string(),
},
);Sourcepub fn include_fields(self, fields: Vec<String>) -> Self
pub fn include_fields(self, fields: Vec<String>) -> Self
Sets the fields to include in the webhook payload.
When specified, only these fields will be included in the webhook payload.
§Example
use shopify_sdk::webhooks::{WebhookRegistrationBuilder, WebhookDeliveryMethod};
use shopify_sdk::rest::resources::v2025_10::common::WebhookTopic;
let registration = WebhookRegistrationBuilder::new(
WebhookTopic::OrdersCreate,
WebhookDeliveryMethod::Http {
uri: "https://example.com/webhooks".to_string(),
},
)
.include_fields(vec!["id".to_string(), "email".to_string()])
.build();
assert_eq!(
registration.include_fields,
Some(vec!["id".to_string(), "email".to_string()])
);Sourcepub fn metafield_namespaces(self, namespaces: Vec<String>) -> Self
pub fn metafield_namespaces(self, namespaces: Vec<String>) -> Self
Sets the metafield namespaces to include in the webhook payload.
§Example
use shopify_sdk::webhooks::{WebhookRegistrationBuilder, WebhookDeliveryMethod};
use shopify_sdk::rest::resources::v2025_10::common::WebhookTopic;
let registration = WebhookRegistrationBuilder::new(
WebhookTopic::ProductsUpdate,
WebhookDeliveryMethod::Http {
uri: "https://example.com/webhooks".to_string(),
},
)
.metafield_namespaces(vec!["custom".to_string(), "app".to_string()])
.build();
assert!(registration.metafield_namespaces.is_some());Sourcepub fn filter(self, filter: String) -> Self
pub fn filter(self, filter: String) -> Self
Sets the filter string for the webhook subscription.
§Example
use shopify_sdk::webhooks::{WebhookRegistrationBuilder, WebhookDeliveryMethod};
use shopify_sdk::rest::resources::v2025_10::common::WebhookTopic;
let registration = WebhookRegistrationBuilder::new(
WebhookTopic::OrdersCreate,
WebhookDeliveryMethod::Http {
uri: "https://example.com/webhooks".to_string(),
},
)
.filter("status:active".to_string())
.build();
assert_eq!(registration.filter, Some("status:active".to_string()));Sourcepub fn handler(self, handler: impl WebhookHandler + 'static) -> Self
pub fn handler(self, handler: impl WebhookHandler + 'static) -> Self
Sets the handler for processing incoming webhooks.
The handler will be invoked by WebhookRegistry::process()
after webhook signature verification succeeds.
§Example
use shopify_sdk::webhooks::{
WebhookRegistrationBuilder, WebhookHandler, WebhookContext, WebhookError, BoxFuture,
WebhookDeliveryMethod
};
use shopify_sdk::rest::resources::v2025_10::common::WebhookTopic;
use serde_json::Value;
struct MyHandler;
impl WebhookHandler for MyHandler {
fn handle<'a>(
&'a self,
_context: WebhookContext,
_payload: Value,
) -> BoxFuture<'a, Result<(), WebhookError>> {
Box::pin(async move {
println!("Webhook received!");
Ok(())
})
}
}
let registration = WebhookRegistrationBuilder::new(
WebhookTopic::OrdersCreate,
WebhookDeliveryMethod::Http {
uri: "https://example.com/webhooks/orders".to_string(),
},
)
.handler(MyHandler)
.build();Sourcepub fn build(self) -> WebhookRegistration
pub fn build(self) -> WebhookRegistration
Builds the WebhookRegistration.
This method is infallible since required fields are set in the constructor.
§Example
use shopify_sdk::webhooks::{WebhookRegistrationBuilder, WebhookDeliveryMethod};
use shopify_sdk::rest::resources::v2025_10::common::WebhookTopic;
let registration = WebhookRegistrationBuilder::new(
WebhookTopic::CustomersCreate,
WebhookDeliveryMethod::Http {
uri: "https://example.com/webhooks/customers".to_string(),
},
)
.build();
assert_eq!(registration.topic, WebhookTopic::CustomersCreate);