Skip to main content

HtmlTemplatesResource

Struct HtmlTemplatesResource 

Source
pub struct HtmlTemplatesResource<'a> { /* private fields */ }
Expand description

client.html_templates()

Implementations§

Source§

impl<'a> HtmlTemplatesResource<'a>

Source

pub fn create(&self, body: &HtmlTemplateCreate) -> Result<HtmlTemplate>

Create a private or shared HTML template

POST /htmltemplates

Creates metadata and optional independent HTML/MJML files. The current user becomes owner even for a global template. email and bulkletter allow private templates (isGlobal defaults to false); groupmember-document and both donation-receipt types require isGlobal=true. Global creation requires the matching template domain’s administration permission. Neither source is required, so an empty template can be created. Source text is stored without rendering placeholders or compiling MJML. copyAssetsFromId copies only image files after template creation has committed; a copy failure can leave the new template and some assets in place. The current copy path does not check visibility of the source template.

§Example
let body = models::HtmlTemplateCreate {
    domain_type: "email".into(),
    name: "Welcome email".into(),
    ..Default::default()
};
let result = client.html_templates().create(&body)?;
println!("{}", result.name);
Source

pub fn delete( &self, template_id: impl Display, query: &DeleteHtmltemplatesTemplateIdQuery, ) -> Result<()>

Check dependencies or delete an HTML template

DELETE /htmltemplates/{templateId}

Requires permission to edit the template (ownership or the domain’s global-template editing permission). Send dryRun explicitly. dryRun=true always returns 409 with a dependency report, even when deletion is allowed; it never returns a successful 204 preview. dryRun=false deletes an unblocked template, its HTML/MJML content files and image assets, then returns 204 without a body. References from group membership emails, bulk letters and group-role document configuration can block deletion, along with registered database dependency checks. An already missing template returns 404. Deleting a global template also invalidates cached authorization data.

§Example
let query = DeleteHtmltemplatesTemplateIdQuery {
    dry_run: Some(true),
    ..Default::default()
};
client.html_templates().delete(2, &query)?;
Source

pub fn get(&self, template_id: impl Display) -> Result<HtmlTemplate>

Get HTML template metadata

GET /htmltemplates/{templateId}

Returns metadata and content-file IDs for one visible template. Owners may view their own private or global templates; other users need the matching domain’s permission to view a global template. This endpoint does not return HTML/MJML source or asset contents. Use the html/mjml content routes or export for those. A template may exist with both content-file IDs null. Missing templates return 404; an existing inaccessible template returns 403.

§Example
let html_template = client.html_templates().get(2)?;
println!("{}", html_template.name);
Source

pub fn get_export(&self, template_id: impl Display) -> Result<String>

Create a downloadable template export

GET /htmltemplates/{templateId}/export

Requires the same template visibility as GET /htmltemplates/{templateId}. Generates and stores a JSON export file, then returns its relative download URL in data; the export is not embedded in this response. The file contains name, domainType, html, mjml and assets. Each asset contains its name, fileHash and base64-encoded content. Ownership, global/private state and template metadata are not exported. The export file is scheduled for deletion after 30 days. This GET creates a new stored file on each call; missing content files or asset failures can prevent export.

§Example
let result = client.html_templates().get_export(2)?;
println!("{:?}", result);
Source

pub fn get_html(&self, template_id: impl Display) -> Result<Option<String>>

Read stored HTML template source

GET /htmltemplates/{templateId}/html

Returns the HTML source as a string inside the JSON data property. Requires template ownership or permission to view the global template. No placeholders are rendered, HTML is not sanitized by this read endpoint, and stored MJML is not compiled as a fallback. data=null means no HTML file is attached; an attached but missing file instead results in 404. The response is application/json rather than text/html.

§Example
let result = client.html_templates().get_html(2)?;
println!("{:?}", result);
Source

pub fn get_mjml(&self, template_id: impl Display) -> Result<Option<String>>

Read stored MJML template source

GET /htmltemplates/{templateId}/mjml

Returns the MJML editor source as a string inside the JSON data property. Requires template ownership or permission to view the global template. The source is returned unchanged, without compilation, placeholder rendering or validation; no MJML is inferred from an HTML file. data=null means no MJML file is attached. A referenced but missing content file results in 404. The response has no meta envelope.

§Example
let result = client.html_templates().get_mjml(2)?;
println!("{:?}", result);
Source

pub fn list(&self, query: &GetHtmltemplatesQuery) -> Result<Vec<HtmlTemplate>>

List visible templates for one purpose

GET /htmltemplates

Lists templates of exactly one required domain type, ordered by name. By default it includes the current user’s own templates and global templates allowed by the corresponding domain policy. Global does not mean public. onlyOwn=true filters by ownership, so it can include global templates owned by the current user. Other users’ private templates are omitted. The response contains metadata and file IDs, not source text or assets. Results are unpaginated; meta.count counts returned templates. domain_type is required unless its deprecated alias type is supplied; there is no default domain.

§Example
let query = GetHtmltemplatesQuery {
    domain_type: Some("email".into()),
    ..Default::default()
};
for html_template in client.html_templates().list(&query)? {
    println!("{}", html_template.name);
}
Source

pub fn patch( &self, template_id: impl Display, body: &HtmlTemplateUpdate, ) -> Result<HtmlTemplate>

Update template metadata or replace source content

PATCH /htmltemplates/{templateId}

Requires template editing permission. If the resulting template is global, the domain’s global-template administration permission is additionally required, even when isGlobal is omitted. The template owner is retained when changing visibility. Private templates are allowed only for email/bulkletter; an email template referenced by group membership emails cannot become private. Omitted/null values preserve fields; content cannot be cleared by sending null. HTML and MJML replacements run first. A truthy htmlFileId is processed last, must belong to this template or be the current user’s unbound html_template upload, and replaces the HTML reference while deleting other content files and clearing MJML. Supply either content or htmlFileId to avoid unintentionally replacing just-written files. domainType and owner are not changed by this route.

§Example
let body = models::HtmlTemplateUpdate {
    name: Some(Some("Updated welcome email".into())),
    ..Default::default()
};
let result = client.html_templates().patch(2, &body)?;
println!("{}", result.name);
Source

pub fn upload_assets( &self, template_id: impl Display, files: &[Upload], ) -> Result<Vec<HtmlTemplateAssetUpload>>

Upload image assets to a template

POST /htmltemplates/{templateId}/uploadassets

Requires permission to edit the template. Send one or more multipart file parts named files[]. The controller accepts client media types beginning with image/; it does not limit uploads to PNG. Files are saved as separate template image assets and returned in input order as editor descriptors. HTML and MJML source are not modified automatically. All client media-type headers are checked before storage, but files are then saved individually; a later storage failure can leave earlier assets persisted. This response has no meta envelope.

§Example
let file = Upload::from_path("logo.png")?;
for html_template in client.html_templates().upload_assets(2, &[file])? {
    println!("{}", html_template.name);
}

Trait Implementations§

Source§

impl<'a> Clone for HtmlTemplatesResource<'a>

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<'a> Copy for HtmlTemplatesResource<'a>

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