# Campaigns ## Create Campaign `print_mail.campaigns.create(CampaignCreateParams**kwargs) -> Campaign` **post** `/print-mail/v1/campaigns` Create a new campaign. A campaign links a mailing list with a specific mail piece profile (letter, postcard, cheque, or self-mailer) to send bulk mail. Upon creation, the campaign enters the `drafting` status while assets are validated. ### Parameters - `mailing_list: str` The ID of the mailing list associated with this campaign. - `cheque_profile: Optional[str]` The ID of the cheque profile used for this campaign, if applicable. - `default_sender_contact: Optional[str]` The ID of the default sender contact to use for orders if not specified per recipient. - `description: Optional[str]` An optional string describing this resource. Will be visible in the API and the dashboard. - `letter_profile: Optional[str]` The ID of the letter profile used for this campaign, if applicable. - `metadata: Optional[Dict[str, object]]` See the section on Metadata. - `postcard_profile: Optional[str]` The ID of the postcard profile used for this campaign, if applicable. - `self_mailer_profile: Optional[str]` The ID of the self-mailer profile used for this campaign, if applicable. - `send_date: Optional[Union[str, datetime]]` The scheduled date and time for the campaign to be sent. - `idempotency_key: Optional[str]` ### Returns - `class Campaign: …` Represents a bulk mail campaign. - `id: str` A unique ID prefixed with campaign_ - `created_at: datetime` The UTC time at which this resource was created. - `created_count: int` The number of orders successfully created for this campaign. - `live: bool` `true` if this is a live mode resource else `false`. - `mailing_list: str` The ID of the mailing list associated with this campaign. - `status: Literal["drafting", "changes_required", "creating_orders", 4 more]` Status of the campaign lifecycle. - `"drafting"` - `"changes_required"` - `"creating_orders"` - `"draft"` - `"ready"` - `"printing"` - `"processed_for_delivery"` - `updated_at: datetime` The UTC time at which this resource was last updated. - `cheque_profile: Optional[str]` The ID of the cheque profile used for this campaign, if applicable. - `default_sender_contact: Optional[str]` The ID of the default sender contact to use for orders if not specified per recipient. - `description: Optional[str]` An optional string describing this resource. Will be visible in the API and the dashboard. - `errors: Optional[List[Error]]` A list of processing errors encountered, if any. Present when status is 'changes_required'. - `message: str` A human-readable message describing the error. - `type: Literal["processing_error", "internal_error"]` Type of error encountered during campaign processing. - `"processing_error"` - `"internal_error"` - `letter_profile: Optional[str]` The ID of the letter profile used for this campaign, if applicable. - `metadata: Optional[Dict[str, object]]` See the section on Metadata. - `order_preview_url: Optional[str]` A temporary URL to preview the first rendered order, available once the campaign status is 'draft' or later. - `postcard_profile: Optional[str]` The ID of the postcard profile used for this campaign, if applicable. - `report_url: Optional[str]` A temporary URL to download the processing report, available once the campaign is in the `ready` status. - `self_mailer_profile: Optional[str]` The ID of the self-mailer profile used for this campaign, if applicable. - `send_date: Optional[datetime]` The scheduled date and time for the campaign to be sent. ### Example ```python import os from postgrid import PostGrid client = PostGrid( print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"), # This is the default and can be omitted ) campaign = client.print_mail.campaigns.create( mailing_list="mailingList", ) print(campaign.id) ``` #### Response ```json { "id": "campaign_sqF12lZ1VlBb", "createdAt": "2019-12-27T18:11:19.117Z", "createdCount": 0, "live": true, "mailingList": "mailingList", "status": "drafting", "updatedAt": "2019-12-27T18:11:19.117Z", "chequeProfile": "chequeProfile", "defaultSenderContact": "defaultSenderContact", "description": "description", "errors": [ { "message": "message", "type": "processing_error" } ], "letterProfile": "letterProfile", "metadata": { "foo": "bar" }, "orderPreviewURL": "https://example.com", "postcardProfile": "postcardProfile", "reportURL": "https://example.com", "selfMailerProfile": "selfMailerProfile", "sendDate": "2019-12-27T18:11:19.117Z" } ``` ## List Campaigns `print_mail.campaigns.list(CampaignListParams**kwargs) -> SyncSkipLimit[Campaign]` **get** `/print-mail/v1/campaigns` Retrieve a list of campaigns. Returns a paginated list of campaigns associated with the authenticated organization, filterable by various parameters. ### Parameters - `limit: Optional[int]` - `search: Optional[str]` You can supply any string to help narrow down the list of resources. For example, if you pass `"New York"` (quoted), it will return resources that have that string present somewhere in their response. Alternatively, you can supply a structured search query. See the documentation on `StructuredSearchQuery` for more details. - `skip: Optional[int]` ### Returns - `class Campaign: …` Represents a bulk mail campaign. - `id: str` A unique ID prefixed with campaign_ - `created_at: datetime` The UTC time at which this resource was created. - `created_count: int` The number of orders successfully created for this campaign. - `live: bool` `true` if this is a live mode resource else `false`. - `mailing_list: str` The ID of the mailing list associated with this campaign. - `status: Literal["drafting", "changes_required", "creating_orders", 4 more]` Status of the campaign lifecycle. - `"drafting"` - `"changes_required"` - `"creating_orders"` - `"draft"` - `"ready"` - `"printing"` - `"processed_for_delivery"` - `updated_at: datetime` The UTC time at which this resource was last updated. - `cheque_profile: Optional[str]` The ID of the cheque profile used for this campaign, if applicable. - `default_sender_contact: Optional[str]` The ID of the default sender contact to use for orders if not specified per recipient. - `description: Optional[str]` An optional string describing this resource. Will be visible in the API and the dashboard. - `errors: Optional[List[Error]]` A list of processing errors encountered, if any. Present when status is 'changes_required'. - `message: str` A human-readable message describing the error. - `type: Literal["processing_error", "internal_error"]` Type of error encountered during campaign processing. - `"processing_error"` - `"internal_error"` - `letter_profile: Optional[str]` The ID of the letter profile used for this campaign, if applicable. - `metadata: Optional[Dict[str, object]]` See the section on Metadata. - `order_preview_url: Optional[str]` A temporary URL to preview the first rendered order, available once the campaign status is 'draft' or later. - `postcard_profile: Optional[str]` The ID of the postcard profile used for this campaign, if applicable. - `report_url: Optional[str]` A temporary URL to download the processing report, available once the campaign is in the `ready` status. - `self_mailer_profile: Optional[str]` The ID of the self-mailer profile used for this campaign, if applicable. - `send_date: Optional[datetime]` The scheduled date and time for the campaign to be sent. ### Example ```python import os from postgrid import PostGrid client = PostGrid( print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"), # This is the default and can be omitted ) page = client.print_mail.campaigns.list() page = page.data[0] print(page.id) ``` #### Response ```json { "data": [ { "id": "campaign_sqF12lZ1VlBb", "createdAt": "2019-12-27T18:11:19.117Z", "createdCount": 0, "live": true, "mailingList": "mailingList", "status": "drafting", "updatedAt": "2019-12-27T18:11:19.117Z", "chequeProfile": "chequeProfile", "defaultSenderContact": "defaultSenderContact", "description": "description", "errors": [ { "message": "message", "type": "processing_error" } ], "letterProfile": "letterProfile", "metadata": { "foo": "bar" }, "orderPreviewURL": "https://example.com", "postcardProfile": "postcardProfile", "reportURL": "https://example.com", "selfMailerProfile": "selfMailerProfile", "sendDate": "2019-12-27T18:11:19.117Z" } ], "limit": 0, "object": "list", "skip": 0, "totalCount": 0 } ``` ## Get Campaign `print_mail.campaigns.retrieve(strid) -> Campaign` **get** `/print-mail/v1/campaigns/{id}` Retrieve a specific campaign by its ID. ### Parameters - `id: str` ### Returns - `class Campaign: …` Represents a bulk mail campaign. - `id: str` A unique ID prefixed with campaign_ - `created_at: datetime` The UTC time at which this resource was created. - `created_count: int` The number of orders successfully created for this campaign. - `live: bool` `true` if this is a live mode resource else `false`. - `mailing_list: str` The ID of the mailing list associated with this campaign. - `status: Literal["drafting", "changes_required", "creating_orders", 4 more]` Status of the campaign lifecycle. - `"drafting"` - `"changes_required"` - `"creating_orders"` - `"draft"` - `"ready"` - `"printing"` - `"processed_for_delivery"` - `updated_at: datetime` The UTC time at which this resource was last updated. - `cheque_profile: Optional[str]` The ID of the cheque profile used for this campaign, if applicable. - `default_sender_contact: Optional[str]` The ID of the default sender contact to use for orders if not specified per recipient. - `description: Optional[str]` An optional string describing this resource. Will be visible in the API and the dashboard. - `errors: Optional[List[Error]]` A list of processing errors encountered, if any. Present when status is 'changes_required'. - `message: str` A human-readable message describing the error. - `type: Literal["processing_error", "internal_error"]` Type of error encountered during campaign processing. - `"processing_error"` - `"internal_error"` - `letter_profile: Optional[str]` The ID of the letter profile used for this campaign, if applicable. - `metadata: Optional[Dict[str, object]]` See the section on Metadata. - `order_preview_url: Optional[str]` A temporary URL to preview the first rendered order, available once the campaign status is 'draft' or later. - `postcard_profile: Optional[str]` The ID of the postcard profile used for this campaign, if applicable. - `report_url: Optional[str]` A temporary URL to download the processing report, available once the campaign is in the `ready` status. - `self_mailer_profile: Optional[str]` The ID of the self-mailer profile used for this campaign, if applicable. - `send_date: Optional[datetime]` The scheduled date and time for the campaign to be sent. ### Example ```python import os from postgrid import PostGrid client = PostGrid( print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"), # This is the default and can be omitted ) campaign = client.print_mail.campaigns.retrieve( "id", ) print(campaign.id) ``` #### Response ```json { "id": "campaign_sqF12lZ1VlBb", "createdAt": "2019-12-27T18:11:19.117Z", "createdCount": 0, "live": true, "mailingList": "mailingList", "status": "drafting", "updatedAt": "2019-12-27T18:11:19.117Z", "chequeProfile": "chequeProfile", "defaultSenderContact": "defaultSenderContact", "description": "description", "errors": [ { "message": "message", "type": "processing_error" } ], "letterProfile": "letterProfile", "metadata": { "foo": "bar" }, "orderPreviewURL": "https://example.com", "postcardProfile": "postcardProfile", "reportURL": "https://example.com", "selfMailerProfile": "selfMailerProfile", "sendDate": "2019-12-27T18:11:19.117Z" } ``` ## Update Campaign `print_mail.campaigns.update(strid, CampaignUpdateParams**kwargs) -> Campaign` **post** `/print-mail/v1/campaigns/{id}` Update an existing campaign. Campaigns can only be updated if they are in the `draft` or `changes_required` status. Updating a campaign will trigger reprocessing and set its status back to `drafting`. ### Parameters - `id: str` - `cheque_profile: Optional[str]` The ID of the cheque profile to use. Setting this will remove other profile types. Set to `null` to remove. - `default_sender_contact: Optional[str]` The ID of the default sender contact. Set to `null` to remove. - `description: Optional[str]` An optional description for the campaign. Set to `null` to remove the existing description. - `letter_profile: Optional[str]` The ID of the letter profile to use. Setting this will remove other profile types. Set to `null` to remove. - `mailing_list: Optional[str]` The ID of the mailing list to associate with this campaign. - `metadata: Optional[Dict[str, str]]` Optional key-value data associated with the campaign. Set to `null` to remove existing metadata. - `postcard_profile: Optional[str]` The ID of the postcard profile to use. Setting this will remove other profile types. Set to `null` to remove. - `self_mailer_profile: Optional[str]` The ID of the self-mailer profile to use. Setting this will remove other profile types. Set to `null` to remove. ### Returns - `class Campaign: …` Represents a bulk mail campaign. - `id: str` A unique ID prefixed with campaign_ - `created_at: datetime` The UTC time at which this resource was created. - `created_count: int` The number of orders successfully created for this campaign. - `live: bool` `true` if this is a live mode resource else `false`. - `mailing_list: str` The ID of the mailing list associated with this campaign. - `status: Literal["drafting", "changes_required", "creating_orders", 4 more]` Status of the campaign lifecycle. - `"drafting"` - `"changes_required"` - `"creating_orders"` - `"draft"` - `"ready"` - `"printing"` - `"processed_for_delivery"` - `updated_at: datetime` The UTC time at which this resource was last updated. - `cheque_profile: Optional[str]` The ID of the cheque profile used for this campaign, if applicable. - `default_sender_contact: Optional[str]` The ID of the default sender contact to use for orders if not specified per recipient. - `description: Optional[str]` An optional string describing this resource. Will be visible in the API and the dashboard. - `errors: Optional[List[Error]]` A list of processing errors encountered, if any. Present when status is 'changes_required'. - `message: str` A human-readable message describing the error. - `type: Literal["processing_error", "internal_error"]` Type of error encountered during campaign processing. - `"processing_error"` - `"internal_error"` - `letter_profile: Optional[str]` The ID of the letter profile used for this campaign, if applicable. - `metadata: Optional[Dict[str, object]]` See the section on Metadata. - `order_preview_url: Optional[str]` A temporary URL to preview the first rendered order, available once the campaign status is 'draft' or later. - `postcard_profile: Optional[str]` The ID of the postcard profile used for this campaign, if applicable. - `report_url: Optional[str]` A temporary URL to download the processing report, available once the campaign is in the `ready` status. - `self_mailer_profile: Optional[str]` The ID of the self-mailer profile used for this campaign, if applicable. - `send_date: Optional[datetime]` The scheduled date and time for the campaign to be sent. ### Example ```python import os from postgrid import PostGrid client = PostGrid( print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"), # This is the default and can be omitted ) campaign = client.print_mail.campaigns.update( id="id", ) print(campaign.id) ``` #### Response ```json { "id": "campaign_sqF12lZ1VlBb", "createdAt": "2019-12-27T18:11:19.117Z", "createdCount": 0, "live": true, "mailingList": "mailingList", "status": "drafting", "updatedAt": "2019-12-27T18:11:19.117Z", "chequeProfile": "chequeProfile", "defaultSenderContact": "defaultSenderContact", "description": "description", "errors": [ { "message": "message", "type": "processing_error" } ], "letterProfile": "letterProfile", "metadata": { "foo": "bar" }, "orderPreviewURL": "https://example.com", "postcardProfile": "postcardProfile", "reportURL": "https://example.com", "selfMailerProfile": "selfMailerProfile", "sendDate": "2019-12-27T18:11:19.117Z" } ``` ## Delete Campaign `print_mail.campaigns.delete(strid) -> CampaignDeleteResponse` **delete** `/print-mail/v1/campaigns/{id}` Delete a campaign. Campaigns can only be deleted if they are in `draft`, `changes_required`, or `ready` status. This also permanently deletes associated resources. This operation cannot be undone. ### Parameters - `id: str` ### Returns - `class CampaignDeleteResponse: …` - `id: str` A unique ID prefixed with campaign_ - `deleted: Literal[true]` - `true` ### Example ```python import os from postgrid import PostGrid client = PostGrid( print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"), # This is the default and can be omitted ) campaign = client.print_mail.campaigns.delete( "id", ) print(campaign.id) ``` #### Response ```json { "id": "campaign_sqF12lZ1VlBb", "deleted": true } ``` ## Send Campaign `print_mail.campaigns.send(strid, CampaignSendParams**kwargs) -> Campaign` **post** `/print-mail/v1/campaigns/{id}/send` Send a campaign for processing. This action transitions a campaign from the `draft` status to `creating_orders`. You can optionally specify a future `sendDate`. Once sent, the campaign cannot be updated. ### Parameters - `id: str` - `send_date: Optional[Union[Union[str, datetime], str]]` The date and time the campaign should be sent. Must be in the future. If omitted, defaults to the earliest possible processing date. - `Union[str, datetime]` - `str` ### Returns - `class Campaign: …` Represents a bulk mail campaign. - `id: str` A unique ID prefixed with campaign_ - `created_at: datetime` The UTC time at which this resource was created. - `created_count: int` The number of orders successfully created for this campaign. - `live: bool` `true` if this is a live mode resource else `false`. - `mailing_list: str` The ID of the mailing list associated with this campaign. - `status: Literal["drafting", "changes_required", "creating_orders", 4 more]` Status of the campaign lifecycle. - `"drafting"` - `"changes_required"` - `"creating_orders"` - `"draft"` - `"ready"` - `"printing"` - `"processed_for_delivery"` - `updated_at: datetime` The UTC time at which this resource was last updated. - `cheque_profile: Optional[str]` The ID of the cheque profile used for this campaign, if applicable. - `default_sender_contact: Optional[str]` The ID of the default sender contact to use for orders if not specified per recipient. - `description: Optional[str]` An optional string describing this resource. Will be visible in the API and the dashboard. - `errors: Optional[List[Error]]` A list of processing errors encountered, if any. Present when status is 'changes_required'. - `message: str` A human-readable message describing the error. - `type: Literal["processing_error", "internal_error"]` Type of error encountered during campaign processing. - `"processing_error"` - `"internal_error"` - `letter_profile: Optional[str]` The ID of the letter profile used for this campaign, if applicable. - `metadata: Optional[Dict[str, object]]` See the section on Metadata. - `order_preview_url: Optional[str]` A temporary URL to preview the first rendered order, available once the campaign status is 'draft' or later. - `postcard_profile: Optional[str]` The ID of the postcard profile used for this campaign, if applicable. - `report_url: Optional[str]` A temporary URL to download the processing report, available once the campaign is in the `ready` status. - `self_mailer_profile: Optional[str]` The ID of the self-mailer profile used for this campaign, if applicable. - `send_date: Optional[datetime]` The scheduled date and time for the campaign to be sent. ### Example ```python import os from postgrid import PostGrid client = PostGrid( print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"), # This is the default and can be omitted ) campaign = client.print_mail.campaigns.send( id="id", ) print(campaign.id) ``` #### Response ```json { "id": "campaign_sqF12lZ1VlBb", "createdAt": "2019-12-27T18:11:19.117Z", "createdCount": 0, "live": true, "mailingList": "mailingList", "status": "drafting", "updatedAt": "2019-12-27T18:11:19.117Z", "chequeProfile": "chequeProfile", "defaultSenderContact": "defaultSenderContact", "description": "description", "errors": [ { "message": "message", "type": "processing_error" } ], "letterProfile": "letterProfile", "metadata": { "foo": "bar" }, "orderPreviewURL": "https://example.com", "postcardProfile": "postcardProfile", "reportURL": "https://example.com", "selfMailerProfile": "selfMailerProfile", "sendDate": "2019-12-27T18:11:19.117Z" } ``` ## Domain Types ### Campaign - `class Campaign: …` Represents a bulk mail campaign. - `id: str` A unique ID prefixed with campaign_ - `created_at: datetime` The UTC time at which this resource was created. - `created_count: int` The number of orders successfully created for this campaign. - `live: bool` `true` if this is a live mode resource else `false`. - `mailing_list: str` The ID of the mailing list associated with this campaign. - `status: Literal["drafting", "changes_required", "creating_orders", 4 more]` Status of the campaign lifecycle. - `"drafting"` - `"changes_required"` - `"creating_orders"` - `"draft"` - `"ready"` - `"printing"` - `"processed_for_delivery"` - `updated_at: datetime` The UTC time at which this resource was last updated. - `cheque_profile: Optional[str]` The ID of the cheque profile used for this campaign, if applicable. - `default_sender_contact: Optional[str]` The ID of the default sender contact to use for orders if not specified per recipient. - `description: Optional[str]` An optional string describing this resource. Will be visible in the API and the dashboard. - `errors: Optional[List[Error]]` A list of processing errors encountered, if any. Present when status is 'changes_required'. - `message: str` A human-readable message describing the error. - `type: Literal["processing_error", "internal_error"]` Type of error encountered during campaign processing. - `"processing_error"` - `"internal_error"` - `letter_profile: Optional[str]` The ID of the letter profile used for this campaign, if applicable. - `metadata: Optional[Dict[str, object]]` See the section on Metadata. - `order_preview_url: Optional[str]` A temporary URL to preview the first rendered order, available once the campaign status is 'draft' or later. - `postcard_profile: Optional[str]` The ID of the postcard profile used for this campaign, if applicable. - `report_url: Optional[str]` A temporary URL to download the processing report, available once the campaign is in the `ready` status. - `self_mailer_profile: Optional[str]` The ID of the self-mailer profile used for this campaign, if applicable. - `send_date: Optional[datetime]` The scheduled date and time for the campaign to be sent.