Skip to main content

WebhookRegistrationBuilder

Struct WebhookRegistrationBuilder 

Source
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

Source

pub fn new(topic: WebhookTopic, delivery_method: WebhookDeliveryMethod) -> Self

Creates a new builder with the required fields.

§Arguments
  • topic - The webhook topic to subscribe to
  • delivery_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(),
    },
);
Source

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()])
);
Source

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());
Source

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()));
Source

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();
Source

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);

Trait Implementations§

Source§

impl Debug for WebhookRegistrationBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more