Class: HubSpotSDK::Resources::Marketing::Emails

Inherits:
Object
  • Object
show all
Defined in:
lib/hubspot_sdk/resources/marketing/emails.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Emails

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Emails.

Parameters:



666
667
668
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 666

def initialize(client:)
  @client = client
end

Instance Method Details

#clone_(id:, clone_name: nil, language: nil, request_options: {}) ⇒ HubSpotSDK::Models::Marketing::PublicEmail

This will create a duplicate email with the same properties as the original, with the exception of a unique ID.

Parameters:

  • id (String)

    The email ID.

  • clone_name (String)

    The name to assign to the cloned email.

  • language (String)

    The language code for the cloned email, such as ‘en’ for English.

  • request_options (HubSpotSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



260
261
262
263
264
265
266
267
268
269
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 260

def clone_(params)
  parsed, options = HubSpotSDK::Marketing::EmailCloneParams.dump_request(params)
  @client.request(
    method: :post,
    path: "marketing/emails/2026-03/clone",
    body: parsed,
    model: HubSpotSDK::Marketing::PublicEmail,
    options: options
  )
end

#create(active_domain: nil, archived: nil, business_unit_id: nil, campaign: nil, content: nil, feedback_survey_id: nil, folder_id_v2: nil, from: nil, jitter_send_time: nil, language: nil, name: nil, publish_date: nil, rss_data: nil, send_on_publish: nil, state: nil, subcategory: nil, subject: nil, subscription_details: nil, testing: nil, to: nil, webversion: nil, request_options: {}) ⇒ HubSpotSDK::Models::Marketing::PublicEmail

Some parameter documentations has been truncated, see Models::Marketing::EmailCreateParams for more details.

Parameters:

Returns:

See Also:



59
60
61
62
63
64
65
66
67
68
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 59

def create(params = {})
  parsed, options = HubSpotSDK::Marketing::EmailCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "marketing/emails/2026-03",
    body: parsed,
    model: HubSpotSDK::Marketing::PublicEmail,
    options: options
  )
end

#create_ab_test_variation(content_id:, variation_name:, request_options: {}) ⇒ HubSpotSDK::Models::Marketing::PublicEmail

Create a variation of a marketing email for an A/B test. The new variation will be created as a draft. If an active variation already exists, a new one won’t be created.

Parameters:

  • content_id (String)

    ID of the object to test.

  • variation_name (String)

    Name of A/B test variation.

  • request_options (HubSpotSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



286
287
288
289
290
291
292
293
294
295
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 286

def create_ab_test_variation(params)
  parsed, options = HubSpotSDK::Marketing::EmailCreateAbTestVariationParams.dump_request(params)
  @client.request(
    method: :post,
    path: "marketing/emails/2026-03/ab-test/create-variation",
    body: parsed,
    model: HubSpotSDK::Marketing::PublicEmail,
    options: options
  )
end

#delete(email_id, archived: nil, request_options: {}) ⇒ nil

Delete a marketing email by its ID

Parameters:

  • email_id (String)
  • archived (Boolean)

    Whether to return only results that have been archived.

  • request_options (HubSpotSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



232
233
234
235
236
237
238
239
240
241
242
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 232

def delete(email_id, params = {})
  parsed, options = HubSpotSDK::Marketing::EmailDeleteParams.dump_request(params)
  query = HubSpotSDK::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :delete,
    path: ["marketing/emails/2026-03/%1$s", email_id],
    query: query,
    model: NilClass,
    options: options
  )
end

#get(email_ids: nil, end_timestamp: nil, property: nil, start_timestamp: nil, request_options: {}) ⇒ HubSpotSDK::Models::Marketing::AggregateEmailStatistics

Use this endpoint to get aggregated statistics of emails sent in a specified time span. It also returns the list of emails that were sent during the time span.

Parameters:

  • email_ids (Array<Integer>)
  • end_timestamp (String)
  • property (String)
  • start_timestamp (String)
  • request_options (HubSpotSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 312

def get(params = {})
  parsed, options = HubSpotSDK::Marketing::EmailGetParams.dump_request(params)
  query = HubSpotSDK::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "marketing/emails/2026-03/statistics/list",
    query: query.transform_keys(
      email_ids: "emailIds",
      end_timestamp: "endTimestamp",
      start_timestamp: "startTimestamp"
    ),
    model: HubSpotSDK::Marketing::AggregateEmailStatistics,
    options: options
  )
end

#get_ab_test_variation(email_id, archived: nil, included_properties: nil, include_stats: nil, marketing_campaign_names: nil, variant_stats: nil, workflow_names: nil, request_options: {}) ⇒ HubSpotSDK::Models::Marketing::PublicEmail

This endpoint lets you obtain the variation of an A/B marketing email. If the email is variation A (master) it will return variation B (variant) and vice versa.

Parameters:

  • email_id (String)
  • archived (Boolean)

    Whether to return only results that have been archived.

  • included_properties (Array<String>)
  • include_stats (Boolean)
  • marketing_campaign_names (Boolean)
  • variant_stats (Boolean)
  • workflow_names (Boolean)
  • request_options (HubSpotSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 353

def get_ab_test_variation(email_id, params = {})
  parsed, options = HubSpotSDK::Marketing::EmailGetAbTestVariationParams.dump_request(params)
  query = HubSpotSDK::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["marketing/emails/2026-03/%1$s/ab-test/get-variation", email_id],
    query: query.transform_keys(
      included_properties: "includedProperties",
      include_stats: "includeStats",
      marketing_campaign_names: "marketingCampaignNames",
      variant_stats: "variantStats",
      workflow_names: "workflowNames"
    ),
    model: HubSpotSDK::Marketing::PublicEmail,
    options: options
  )
end

#get_draft(email_id, request_options: {}) ⇒ HubSpotSDK::Models::Marketing::PublicEmail

Get the draft version of an email (if it exists). If no draft version exists, the published email is returned.

Parameters:

Returns:

See Also:



382
383
384
385
386
387
388
389
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 382

def get_draft(email_id, params = {})
  @client.request(
    method: :get,
    path: ["marketing/emails/2026-03/%1$s/draft", email_id],
    model: HubSpotSDK::Marketing::PublicEmail,
    options: params[:request_options]
  )
end

#get_histogram(email_ids: nil, end_timestamp: nil, interval: nil, start_timestamp: nil, request_options: {}) ⇒ HubSpotSDK::Models::Marketing::CollectionResponseWithTotalEmailStatisticInterval

Get aggregated statistics in intervals for a specified time span. Each interval contains aggregated statistics of the emails that were sent in that time.

Parameters:

Returns:

See Also:



405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 405

def get_histogram(params = {})
  parsed, options = HubSpotSDK::Marketing::EmailGetHistogramParams.dump_request(params)
  query = HubSpotSDK::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "marketing/emails/2026-03/statistics/histogram",
    query: query.transform_keys(
      email_ids: "emailIds",
      end_timestamp: "endTimestamp",
      start_timestamp: "startTimestamp"
    ),
    model: HubSpotSDK::Marketing::CollectionResponseWithTotalEmailStatisticInterval,
    options: options
  )
end

#get_revision(revision_id, email_id:, request_options: {}) ⇒ HubSpotSDK::Models::Marketing::PublicEmailVersion

Get a specific revision of a marketing email.

Parameters:

Returns:

See Also:



432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 432

def get_revision(revision_id, params)
  parsed, options = HubSpotSDK::Marketing::EmailGetRevisionParams.dump_request(params)
  email_id =
    parsed.delete(:email_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["marketing/emails/2026-03/%1$s/revisions/%2$s", email_id, revision_id],
    model: HubSpotSDK::Marketing::PublicEmailVersion,
    options: options
  )
end

#list(after: nil, archived: nil, campaign: nil, created_after: nil, created_at: nil, created_before: nil, included_properties: nil, include_stats: nil, is_published: nil, limit: nil, marketing_campaign_names: nil, published_after: nil, published_at: nil, published_before: nil, sort: nil, type: nil, updated_after: nil, updated_at: nil, updated_before: nil, variant_stats: nil, workflow_names: nil, request_options: {}) ⇒ HubSpotSDK::Internal::Page<HubSpotSDK::Models::Marketing::PublicEmail>

Some parameter documentations has been truncated, see Models::Marketing::EmailListParams for more details.

Parameters:

  • after (String)

    The paging cursor token of the last successfully read resource will be returned

  • archived (Boolean)

    Whether to return only results that have been archived.

  • campaign (String)
  • created_after (Time)
  • created_at (Time)
  • created_before (Time)
  • included_properties (Array<String>)
  • include_stats (Boolean)
  • is_published (Boolean)
  • limit (Integer)

    The maximum number of results to display per page.

  • marketing_campaign_names (Boolean)
  • published_after (Time)
  • published_at (Time)
  • published_before (Time)
  • sort (Array<String>)
  • type (Symbol, HubSpotSDK::Models::Marketing::EmailListParams::Type)
  • updated_after (Time)
  • updated_at (Time)
  • updated_before (Time)
  • variant_stats (Boolean)
  • workflow_names (Boolean)
  • request_options (HubSpotSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 190

def list(params = {})
  parsed, options = HubSpotSDK::Marketing::EmailListParams.dump_request(params)
  query = HubSpotSDK::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "marketing/emails/2026-03",
    query: query.transform_keys(
      created_after: "createdAfter",
      created_at: "createdAt",
      created_before: "createdBefore",
      included_properties: "includedProperties",
      include_stats: "includeStats",
      is_published: "isPublished",
      marketing_campaign_names: "marketingCampaignNames",
      published_after: "publishedAfter",
      published_at: "publishedAt",
      published_before: "publishedBefore",
      updated_after: "updatedAfter",
      updated_at: "updatedAt",
      updated_before: "updatedBefore",
      variant_stats: "variantStats",
      workflow_names: "workflowNames"
    ),
    page: HubSpotSDK::Internal::Page,
    model: HubSpotSDK::Marketing::PublicEmail,
    options: options
  )
end

#list_revisions(email_id, after: nil, before: nil, limit: nil, request_options: {}) ⇒ HubSpotSDK::Internal::Page<HubSpotSDK::Models::Marketing::VersionPublicEmail>

Some parameter documentations has been truncated, see Models::Marketing::EmailListRevisionsParams for more details.

Get a list of all versions of a marketing email, with each entry including the full state of that particular version. To view the most recent version, sort by the updatedAt parameter.

Parameters:

  • email_id (String)
  • after (String)

    The paging cursor token of the last successfully read resource will be returned

  • before (String)
  • limit (Integer)

    The maximum number of results to display per page.

  • request_options (HubSpotSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 468

def list_revisions(email_id, params = {})
  parsed, options = HubSpotSDK::Marketing::EmailListRevisionsParams.dump_request(params)
  query = HubSpotSDK::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["marketing/emails/2026-03/%1$s/revisions", email_id],
    query: query,
    page: HubSpotSDK::Internal::Page,
    model: HubSpotSDK::Marketing::VersionPublicEmail,
    options: options
  )
end

#publish(email_id, request_options: {}) ⇒ nil

If you have a Marketing Hub Enterprise account or the transactional email add-on, you can use this endpoint to publish an automated email or send/schedule a regular email.

Parameters:

Returns:

  • (nil)

See Also:



493
494
495
496
497
498
499
500
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 493

def publish(email_id, params = {})
  @client.request(
    method: :post,
    path: ["marketing/emails/2026-03/%1$s/publish", email_id],
    model: NilClass,
    options: params[:request_options]
  )
end

#reset_draft(email_id, request_options: {}) ⇒ nil

Resets the draft back to a copy of the live object.

Parameters:

Returns:

  • (nil)

See Also:



512
513
514
515
516
517
518
519
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 512

def reset_draft(email_id, params = {})
  @client.request(
    method: :post,
    path: ["marketing/emails/2026-03/%1$s/draft/reset", email_id],
    model: NilClass,
    options: params[:request_options]
  )
end

#restore_revision(revision_id, email_id:, request_options: {}) ⇒ nil

Restores a previous revision of a marketing email. The current revision becomes old, and the restored revision is given a new version number.

Parameters:

Returns:

  • (nil)

See Also:



533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 533

def restore_revision(revision_id, params)
  parsed, options = HubSpotSDK::Marketing::EmailRestoreRevisionParams.dump_request(params)
  email_id =
    parsed.delete(:email_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :post,
    path: ["marketing/emails/2026-03/%1$s/revisions/%2$s/restore", email_id, revision_id],
    model: NilClass,
    options: options
  )
end

#restore_revision_to_draft(revision_id, email_id:, request_options: {}) ⇒ HubSpotSDK::Models::Marketing::PublicEmail

Restores a previous revision of a marketing email to DRAFT state. If there is currently something in the draft for that object, it is overwritten.

Parameters:

Returns:

See Also:



559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 559

def restore_revision_to_draft(revision_id, params)
  parsed, options = HubSpotSDK::Marketing::EmailRestoreRevisionToDraftParams.dump_request(params)
  email_id =
    parsed.delete(:email_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :post,
    path: ["marketing/emails/2026-03/%1$s/revisions/%2$s/restore-to-draft", email_id, revision_id],
    model: HubSpotSDK::Marketing::PublicEmail,
    options: options
  )
end

#unpublish(email_id, request_options: {}) ⇒ nil

If you have a Marketing Hub Enterprise account or the transactional email add-on, you can use this endpoint to unpublish an automated email or cancel a regular email. If the email is already in the process of being sent, canceling might not be possible.

Parameters:

Returns:

  • (nil)

See Also:



586
587
588
589
590
591
592
593
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 586

def unpublish(email_id, params = {})
  @client.request(
    method: :post,
    path: ["marketing/emails/2026-03/%1$s/unpublish", email_id],
    model: NilClass,
    options: params[:request_options]
  )
end

#update(email_id, body_archived: nil, active_domain: nil, business_unit_id: nil, campaign: nil, content: nil, folder_id_v2: nil, from: nil, jitter_send_time: nil, language: nil, name: nil, publish_date: nil, rss_data: nil, send_on_publish: nil, state: nil, subcategory: nil, subject: nil, subscription_details: nil, testing: nil, to: nil, webversion: nil, request_options: {}) ⇒ HubSpotSDK::Models::Marketing::PublicEmail

Some parameter documentations has been truncated, see Models::Marketing::EmailUpdateParams for more details.

Change properties of a marketing email.

Parameters:

Returns:

See Also:



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 124

def update(email_id, params = {})
  query_params = [:query_archived]
  parsed, options = HubSpotSDK::Marketing::EmailUpdateParams.dump_request(params)
  query = HubSpotSDK::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :patch,
    path: ["marketing/emails/2026-03/%1$s", email_id],
    query: query.transform_keys(query_archived: "archived"),
    body: parsed.except(*query_params),
    model: HubSpotSDK::Marketing::PublicEmail,
    options: options
  )
end

#update_draft(email_id, active_domain: nil, archived: nil, business_unit_id: nil, campaign: nil, content: nil, folder_id_v2: nil, from: nil, jitter_send_time: nil, language: nil, name: nil, publish_date: nil, rss_data: nil, send_on_publish: nil, state: nil, subcategory: nil, subject: nil, subscription_details: nil, testing: nil, to: nil, webversion: nil, request_options: {}) ⇒ HubSpotSDK::Models::Marketing::PublicEmail

Some parameter documentations has been truncated, see Models::Marketing::EmailUpdateDraftParams for more details.

Create or update the draft version of a marketing email. If no draft exists, the system creates a draft from the current “live” email then applies the request body to that draft. The draft version only lives on the buffer—the email is not cloned.

Parameters:

Returns:

See Also:



652
653
654
655
656
657
658
659
660
661
# File 'lib/hubspot_sdk/resources/marketing/emails.rb', line 652

def update_draft(email_id, params = {})
  parsed, options = HubSpotSDK::Marketing::EmailUpdateDraftParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["marketing/emails/2026-03/%1$s/draft", email_id],
    body: parsed,
    model: HubSpotSDK::Marketing::PublicEmail,
    options: options
  )
end