Skip to main content

BrazeClient

Struct BrazeClient 

Source
pub struct BrazeClient { /* private fields */ }
Expand description

Cheap-to-clone Braze API client. Internally Arc-shares the API key and reqwest::Client’s connection pool, so cloning for a parallel batch is essentially free.

Implementations§

Source§

impl BrazeClient

Source

pub async fn list_catalogs(&self) -> Result<Vec<Catalog>, BrazeApiError>

GET /catalogs — list every catalog schema in the workspace.

Fails closed on next_cursor rather than returning page 1: a partial view would let apply re-create page-2 catalogs and mis-report drift. Mirrors list_content_blocks.

Source

pub async fn get_catalog(&self, name: &str) -> Result<Catalog, BrazeApiError>

GET /catalogs/{name} — fetch a single catalog schema.

404 from Braze and an empty catalogs array in the response are both mapped to BrazeApiError::NotFound so callers can branch on “this catalog doesn’t exist” without string matching on the HTTP body.

Source

pub async fn create_catalog( &self, catalog: &Catalog, ) -> Result<(), BrazeApiError>

POST /catalogs — create a new catalog with its initial schema.

Duplicate names surface as 400 with body error_id: "catalog-name-already-exists" per Braze docs and are propagated to the caller; a subsequent apply will see the existing catalog and no-op on the create.

Source

pub async fn add_catalog_field( &self, catalog_name: &str, field: &CatalogField, ) -> Result<(), BrazeApiError>

POST /catalogs/{name}/fields — add one field to a catalog schema.

ASSUMED wire format {"fields": [{"name": "...", "type": "..."}]} per IMPLEMENTATION.md §8.3 + Braze public docs. v0.1.0 sends one POST per added field.

Source

pub async fn delete_catalog_field( &self, catalog_name: &str, field_name: &str, ) -> Result<(), BrazeApiError>

DELETE /catalogs/{name}/fields/{field} — remove a field. Destructive.

404 from Braze stays as Http { status: 404, .. } rather than being mapped to NotFound. The use case is different from get_catalog: a 404 here means “the field you wanted to delete is already gone”, which is a state-drift signal the user should see rather than silently no-op. A future --ignore-missing flag in apply can opt into idempotent behavior.

Source§

impl BrazeClient

Source

pub async fn list_content_blocks( &self, ) -> Result<Vec<ContentBlockSummary>, BrazeApiError>

Braze has no has_more/cursor field, so we loop until a short page. offset is omitted on the first request because this endpoint rejects offset=0 with 400 "Offset must be greater than 0.".

Source

pub async fn get_content_block( &self, id: &str, ) -> Result<ContentBlock, BrazeApiError>

Braze returns 200 with a non-success message field for unknown ids instead of a 404, so we need to discriminate here rather than relying on HTTP status. Recognised not-found phrases remap to NotFound so callers can branch cleanly; any other non-“success” message surfaces verbatim as UnexpectedApiMessage so a real failure is not silently swallowed. The wire shapes are ASSUMED per IMPLEMENTATION.md §8.3 — a blanket “non-success → NotFound” rule would misclassify every future surprise as a missing id.

Source

pub async fn create_content_block( &self, cb: &ContentBlock, ) -> Result<String, BrazeApiError>

Source

pub async fn update_content_block( &self, id: &str, cb: &ContentBlock, ) -> Result<(), BrazeApiError>

Used both for body changes and for the --archive-orphans rename (same id, [ARCHIVED-...] name).

state is intentionally omitted from the request body. The diff layer excludes it from syncable_eq (there is no state field on /content_blocks/info, so we cannot read it back and cannot compare it), and the README documents it as a local-only field. Forwarding cb.state here would let local edits leak into Braze piggyback-style whenever another field changed, and could silently overwrite a real remote state that braze-sync has no way to observe — the same “infinite drift” trap the honest-orphan design exists to avoid. Leaving state off makes the wire-level behavior match the documented semantics.

Source§

impl BrazeClient

Source

pub async fn list_custom_attributes( &self, ) -> Result<Vec<CustomAttribute>, BrazeApiError>

List all Custom Attributes from Braze. Follows RFC 5988 Link headers through every page until the server stops returning rel="next".

Source

pub async fn set_custom_attribute_blocklist( &self, names: &[&str], blocklisted: bool, ) -> Result<(), BrazeApiError>

Toggle the blocklisted (deprecated) flag on one or more Custom Attributes. This is the only write operation braze-sync performs for Custom Attributes.

Source§

impl BrazeClient

Source

pub async fn list_email_templates( &self, ) -> Result<Vec<EmailTemplateSummary>, BrazeApiError>

Braze has no has_more/cursor field, so we loop until a short page. offset is omitted on the first request because this endpoint rejects offset=0 with 400 "Offset must be greater than 0.".

Source

pub async fn get_email_template( &self, id: &str, ) -> Result<EmailTemplate, BrazeApiError>

Fetch full template details by id. Uses the same 200+message classifier pattern as content_block::get_content_block.

Source

pub async fn create_email_template( &self, et: &EmailTemplate, ) -> Result<String, BrazeApiError>

Source

pub async fn update_email_template( &self, id: &str, et: &EmailTemplate, ) -> Result<(), BrazeApiError>

Update an existing email template. description is intentionally omitted — Braze /info returns it but create/update cannot set it.

Source§

impl BrazeClient

Source

pub fn from_resolved(resolved: &ResolvedConfig) -> Self

Source

pub fn new(base_url: Url, api_key: SecretString) -> Self

Trait Implementations§

Source§

impl Clone for BrazeClient

Source§

fn clone(&self) -> BrazeClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BrazeClient

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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