Skip to main content

LoopsClient

Struct LoopsClient 

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

High-level client for the Loops API.

Wraps every Loops endpoint with typed arguments, maps failures to LoopsError, and enforces safe mode. Cloning is cheap: clones share the underlying connection pool.

use loops_so::{ContactFields, ContactId, LoopsClient};

let client = LoopsClient::builder().api_key("your_api_key").build()?;
client
    .upsert_contact(
        ContactId::email("user@example.com"),
        ContactFields::new().first_name("John"),
    )
    .await?;

Implementations§

Source§

impl LoopsClient

Source

pub async fn list_campaigns(&self, page: Page) -> Result<ListCampaignsResponse>

List campaigns.

Source

pub async fn get_campaign(&self, campaign_id: &str) -> Result<CampaignResponse>

Get a campaign.

Source

pub async fn create_campaign( &self, name: &str, ) -> Result<CreateCampaignResponse>

Create a draft campaign, together with its email message.

Source

pub async fn update_campaign( &self, campaign_id: &str, name: &str, ) -> Result<CampaignResponse>

Rename a campaign.

Source

pub async fn get_campaign_metrics( &self, campaign_id: &str, ) -> Result<EmailMetricsResponse>

All-time engagement metrics of a sent campaign. Opens and clicks count sends, not events: a send opened five times counts once.

§Errors

LoopsError::Api with status 400 when the campaign has not been sent or has no email message.

Source§

impl LoopsClient

Source

pub async fn create_contact( &self, email: &str, user_id: Option<&str>, fields: ContactFields, ) -> Result<ContactSuccessResponse>

Create a contact.

Fails with LoopsError::ContactExists when a contact with this email or user ID already exists; use upsert_contact to create or update.

Source

pub async fn upsert_contact( &self, contact: ContactId, fields: ContactFields, ) -> Result<ContactSuccessResponse>

Create a contact, or update the one matching contact.

To change a contact’s email address the contact needs a user ID: pass ContactId::Both and Loops matches on either value.

Source

pub async fn find_contact( &self, contact: ContactId, ) -> Result<Option<Vec<Contact>>>

Find a contact by email or user ID.

Returns None when Loops answers the lookup with a failure (400 or 404) rather than raising, and Some with the matches otherwise. An unknown contact is usually Some(vec![]). The contacts carry their custom properties in Contact::properties.

§Errors

LoopsError::InvalidInput for ContactId::Both: Loops looks up by exactly one identifier.

Source

pub async fn delete_contact(&self, contact: ContactId) -> Result<bool>

Delete a contact by email or user ID.

Returns true once deleted and false when Loops answers with a failure (400 or 404), e.g. because no such contact exists.

§Errors

LoopsError::InvalidInput for ContactId::Both: Loops deletes by exactly one identifier.

Source

pub async fn create_contact_property( &self, name: &str, property_type: ContactPropertyCreateRequestType, ) -> Result<Value>

Create a custom contact property.

Returns the response body as JSON, since Loops answers with more fields than the spec documents.

Source

pub async fn list_contact_properties(&self) -> Result<Vec<ContactProperty>>

List every contact property, default and custom.

Source

pub async fn list_mailing_lists(&self) -> Result<Vec<MailingList>>

List the team’s mailing lists.

Source

pub async fn list_sending_ips(&self) -> Result<Vec<String>>

List Loops’ dedicated sending IP addresses.

Source

pub async fn get_contact_suppression( &self, contact: ContactId, ) -> Result<ContactSuppressionStatusResponse>

Get a contact’s suppression status and the remaining removal quota.

§Errors

LoopsError::InvalidInput for ContactId::Both.

Source

pub async fn remove_contact_suppression( &self, contact: ContactId, ) -> Result<ContactSuppressionRemoveResponse>

Remove a contact from the suppression list.

§Errors

LoopsError::InvalidInput for ContactId::Both.

Source§

impl LoopsClient

Source

pub async fn get_email_message( &self, email_message_id: &str, ) -> Result<EmailMessageResponse>

Get an email message.

Source

pub async fn update_email_message( &self, email_message_id: &str, update: EmailMessageUpdate, ) -> Result<EmailMessageResponse>

Update an email message. Only the fields set on update change.

§Errors

LoopsError::UnsafeEmail when safe mode is on and the CC or BCC address is outside the allowed domains: those addresses receive every email sent from the message. LoopsError::Api with status 409 when expected_revision_id is stale.

Source

pub async fn get_email_message_guardian( &self, email_message_id: &str, ) -> Result<EmailMessageGuardianResponse>

Run Guardian content checks against a saved email message: missing or invalid links, unsupported properties, malformed buttons, missing required data variables and the like. MJML messages are not supported.

Source

pub async fn preview_email_message( &self, email_message_id: &str, emails: &[&str], options: PreviewOptions, ) -> Result<EmailMessagePreviewResponse>

Send a preview of an email message to one or more addresses, each checked against safe mode.

Source

pub async fn create_upload( &self, content_type: &str, content_length: u64, ) -> Result<CreateUploadResponse>

Start an asset upload. Upload the file to the returned presigned URL, then call complete_upload.

Source

pub async fn complete_upload( &self, upload_id: &str, ) -> Result<CompleteUploadResponse>

Mark an upload as complete.

Loops reports an exceeded upload limit as HTTP 429, which surfaces as LoopsError::RateLimit.

Source§

impl LoopsClient

Source

pub async fn send_event( &self, event_name: &str, contact: ContactId, options: EventOptions, ) -> Result<EventSuccessResponse>

Send an event to trigger workflows and emails for a contact.

An idempotency key is generated when options does not carry one.

Source§

impl LoopsClient

Source

pub async fn list_campaign_groups( &self, page: Page, ) -> Result<ListGroupsResponse>

List campaign groups.

Source

pub async fn get_campaign_group( &self, campaign_group_id: &str, ) -> Result<GroupResponse>

Get a campaign group.

Source

pub async fn create_campaign_group( &self, name: &str, description: Option<&str>, ) -> Result<GroupResponse>

Create a campaign group.

Source

pub async fn update_campaign_group( &self, campaign_group_id: &str, name: Option<&str>, description: Option<&str>, ) -> Result<GroupResponse>

Rename a campaign group and/or change its description.

Source

pub async fn list_transactional_groups( &self, page: Page, ) -> Result<ListGroupsResponse>

List transactional groups.

Source

pub async fn get_transactional_group( &self, transactional_group_id: &str, ) -> Result<GroupResponse>

Get a transactional group.

Source

pub async fn create_transactional_group( &self, name: &str, description: Option<&str>, ) -> Result<GroupResponse>

Create a transactional group.

Source

pub async fn update_transactional_group( &self, transactional_group_id: &str, name: Option<&str>, description: Option<&str>, ) -> Result<GroupResponse>

Rename a transactional group and/or change its description.

Source

pub async fn list_workflow_groups( &self, page: Page, ) -> Result<ListGroupsResponse>

List workflow groups, most recently created first.

Source

pub async fn get_workflow_group( &self, workflow_group_id: &str, ) -> Result<GroupResponse>

Get a workflow group.

Source

pub async fn create_workflow_group( &self, name: &str, description: Option<&str>, ) -> Result<GroupResponse>

Create a workflow group.

Source

pub async fn update_workflow_group( &self, workflow_group_id: &str, name: Option<&str>, description: Option<&str>, ) -> Result<GroupResponse>

Rename a workflow group and/or change its description.

The reserved “Unsorted” group cannot be edited.

Source§

impl LoopsClient

Source

pub async fn list_audience_segments( &self, page: Page, ) -> Result<ListAudienceSegmentsResponse>

List audience segments, most recently created first.

Source

pub async fn get_audience_segment( &self, audience_segment_id: &str, ) -> Result<AudienceSegmentResponse>

Get an audience segment.

Source

pub async fn create_audience_segment( &self, name: &str, filter: Value, description: Option<&str>, ) -> Result<AudienceSegmentResponse>

Create an audience segment.

filter is the segment’s condition tree, e.g. {"match": "all", "conditions": [{"type": "property", "key": "plan", "operator": "equals", "value": "pro"}]}. match is "all" or "any"; each condition is a property, optIn or activity condition (see the Loops docs for the grammar).

Source

pub async fn list_event_patterns( &self, page: Page, ) -> Result<ListEventPatternsResponse>

List event patterns: the event types workflow triggers can listen for, custom or from integrated webhook platforms.

Source

pub async fn get_event_pattern( &self, event_pattern_id: &str, ) -> Result<EventPattern>

Get an event pattern by ID.

Source

pub async fn get_event_pattern_by_name( &self, event_name: &str, ) -> Result<EventPattern>

Get an event pattern by its case-sensitive event name.

Source§

impl LoopsClient

Source

pub async fn list_components( &self, page: Page, ) -> Result<ListComponentsResponse>

List components.

Source

pub async fn get_component( &self, component_id: &str, ) -> Result<ComponentResponse>

Get a component.

Source

pub async fn create_component( &self, name: &str, lmx: &str, ) -> Result<ComponentResponse>

Create a component from an LMX body.

Source

pub async fn update_component( &self, component_id: &str, name: Option<&str>, lmx: Option<&str>, ) -> Result<UpdateComponentResponse>

Rename a component and/or replace its LMX body. Changing the body updates every email using the component; the response counts them in affected_email_count.

Source

pub async fn list_themes(&self, page: Page) -> Result<ListThemesResponse>

List themes.

Source

pub async fn get_theme(&self, theme_id: &str) -> Result<ThemeResponse>

Get a theme.

Source

pub async fn create_theme( &self, name: &str, styles: Option<ThemeStyles>, ) -> Result<ThemeResponse>

Create a theme. styles mirrors the attributes of the LMX <Style /> tag; unset fields keep the Loops defaults.

Source

pub async fn update_theme( &self, theme_id: &str, name: Option<&str>, styles: Option<ThemeStyles>, ) -> Result<UpdateThemeResponse>

Rename a theme and/or change its styles. Changing styles updates every email using the theme; the response counts them in affected_email_count.

Source§

impl LoopsClient

Source

pub async fn send_transactional_email( &self, transactional_id: &str, email: &str, options: TransactionalOptions, ) -> Result<TransactionalSuccessResponse>

Send a transactional email.

An idempotency key is generated when options does not carry one.

§Errors

LoopsError::Api with status 404 when the transactional email does not exist, 409 when the idempotency key was already used, and 400 for other rejections such as an unpublished template.

Source

pub async fn list_transactional_emails( &self, page: Page, ) -> Result<TransactionalEmailsResponse>

List published transactional emails.

Source

pub async fn list_transactional_templates( &self, page: Page, ) -> Result<ListTransactionalsResourceResponse>

List transactional email templates, drafts included.

Source

pub async fn get_transactional_template( &self, transactional_id: &str, ) -> Result<TransactionalResource>

Get a transactional email template.

Source

pub async fn get_transactional_variables( &self, transactional_id: &str, ) -> Result<Vec<String>>

The names of the data variables a transactional email template expects, for building the data_variables of send_transactional_email. Empty for unpublished templates.

Source

pub async fn get_transactional_template_metrics( &self, transactional_id: &str, ) -> Result<TransactionalMetricsResponse>

All-time delivery metrics of a transactional email template, totalled across its published versions.

Source

pub async fn create_transactional_template( &self, name: &str, transactional_group_id: Option<&str>, ) -> Result<TransactionalDraftResponse>

Create a draft transactional email template.

Source

pub async fn update_transactional_template( &self, transactional_id: &str, name: Option<&str>, transactional_group_id: Option<&str>, ) -> Result<TransactionalResource>

Rename a transactional email template or move it to another group.

Source

pub async fn draft_transactional_template( &self, transactional_id: &str, ) -> Result<TransactionalDraftResponse>

Create the draft of a transactional email template, or return the existing one.

Source

pub async fn publish_transactional_template( &self, transactional_id: &str, ) -> Result<TransactionalResource>

Publish the draft of a transactional email template.

Source§

impl LoopsClient

Source

pub async fn get_workflow_node( &self, workflow_id: &str, node_id: &str, ) -> Result<Value>

Get a workflow node as JSON; its shape depends on typeName.

Source

pub async fn get_workflow_node_metrics( &self, workflow_id: &str, node_id: &str, ) -> Result<EmailMetricsResponse>

All-time engagement metrics of a SendEmailAction node. Any other node type fails with 400; a node that has not sent yet reports zeros.

Source

pub async fn create_workflow_node( &self, workflow_id: &str, node_type: CreateWorkflowNodeTypeName, expected_revision_id: Option<&str>, placement: NodePlacement, ) -> Result<Value>

Add a node to a workflow at placement. The node is created with default settings; configure it with update_workflow_node.

Returns the response as JSON: the created node and the updated workflow.

Source

pub async fn update_workflow_node( &self, workflow_id: &str, node_id: &str, expected_revision_id: Option<&str>, payload: Value, ) -> Result<Value>

Update a node’s settings. payload holds the node-type-specific fields, e.g. {"amount": 2, "unit": "d"} for a TimerAction.

Returns the response as JSON: the updated node’s fields plus the latest workflow.

Source

pub async fn add_workflow_branch( &self, workflow_id: &str, node_id: &str, expected_revision_id: Option<&str>, ) -> Result<AddWorkflowBranchResponse>

Add an unconfigured branch to a BranchNode or ExperimentBranchNode.

Source

pub async fn reroute_workflow_node_connection( &self, workflow_id: &str, node_id: &str, expected_revision_id: Option<&str>, new_target_node_id: &str, ) -> Result<Value>

Move the single outgoing connection of node_id to new_target_node_id. Branch nodes have several outputs and cannot be rerouted this way; the old target must keep another incoming connection.

Returns the response as JSON: the updated source node plus the latest workflow.

Source

pub async fn delete_workflow_node( &self, workflow_id: &str, node_id: &str, expected_revision_id: Option<&str>, options: DeleteNodeOptions, ) -> Result<DeleteWorkflowNodeResponse>

Delete a node, or with DeleteNodeOptions::recursive the node and everything downstream of it.

With dry_run, or when contacts are queued at the node, Loops answers with a preview instead of deleting.

Source§

impl LoopsClient

Source

pub async fn list_workflows(&self, page: Page) -> Result<ListWorkflowsResponse>

List workflows.

Source

pub async fn get_workflow( &self, workflow_id: &str, ) -> Result<SimplifiedWorkflow>

Get a workflow with its node graph.

Source

pub async fn create_workflow( &self, name: &str, description: Option<&str>, mailing_list_id: Option<&str>, workflow_group_id: Option<&str>, ) -> Result<SimplifiedWorkflow>

Create a draft workflow with a blank trigger and an exit node. Build out its graph with the workflow node methods.

Without workflow_group_id, Loops files the workflow in the team’s Unsorted group.

Source

pub async fn update_workflow( &self, workflow_id: &str, expected_revision_id: Option<&str>, name: Option<&str>, description: Option<&str>, workflow_group_id: Option<&str>, ) -> Result<SimplifiedWorkflow>

Rename a workflow, change its description, and/or move it to another workflow group. At least one of the three must be Some, or the call fails with LoopsError::InvalidInput before any request is sent.

expected_revision_id is the optimistic concurrency token: pass the latest workflow_revision_id, or None for a workflow that has none yet. A stale value fails with 409.

Source

pub async fn change_workflow_mailing_list( &self, workflow_id: &str, expected_revision_id: Option<&str>, mailing_list_id: Option<&str>, dry_run: Option<bool>, queued_contact_policy: Option<WorkflowQueuedContactPolicy>, ) -> Result<ChangeWorkflowMailingListResponse>

Set (Some) or clear (None) the mailing list of a workflow.

With dry_run, or when contacts queued in the workflow would be excluded by the new list, Loops answers with a preview instead of applying the change; retry with WorkflowQueuedContactPolicy::Discard to apply it and discard them.

Source

pub async fn delete_workflow( &self, workflow_id: &str, expected_revision_id: Option<&str>, confirm_delete: Option<bool>, ) -> Result<bool>

Delete a workflow. Returns true once deleted.

A workflow that is sending or still has queued contacts is not deleted on the first attempt: Loops answers 409 saying what stands in the way. Retry with confirm_delete: Some(true) to delete it, stop sending and cancel the queued contacts.

Source§

impl LoopsClient

Source

pub fn new() -> Result<Self>

A client built entirely from the process-wide defaults.

§Errors

See LoopsClientBuilder::build.

Source

pub fn builder() -> LoopsClientBuilder

Start building a client.

Source

pub fn base_url(&self) -> &str

The normalized base URL requests are sent to.

Source

pub fn safe_mode(&self) -> bool

Whether safe mode is on for this client.

Source

pub fn low_level(&self) -> Result<LoopsOpenApiSpecClient>

A low-level generated client that shares this client’s base URL and API key. Use it for endpoints or options the high-level methods do not expose. Each call builds a new connection pool, so keep the result rather than calling this per request.

§Errors

LoopsError::Http when the underlying reqwest client cannot be built.

Source

pub async fn health(&self) -> Result<bool>

Validate the API key.

§Errors

LoopsError::Api with status 401 when the key is invalid.

Trait Implementations§

Source§

impl Clone for LoopsClient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for LoopsClient

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: Sized + 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: Sized + 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 = !

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

fn try_from(value: U) -> Result<T, !>

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