# Campaigns ## Create 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. ### Header Parameters - `"idempotency-key": optional string` ### Body Parameters - `mailingList: string` The ID of the mailing list associated with this campaign. - `chequeProfile: optional string` The ID of the cheque profile used for this campaign, if applicable. - `defaultSenderContact: optional string` The ID of the default sender contact to use for orders if not specified per recipient. - `description: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `letterProfile: optional string` The ID of the letter profile used for this campaign, if applicable. - `metadata: optional map[unknown]` See the section on Metadata. - `postcardProfile: optional string` The ID of the postcard profile used for this campaign, if applicable. - `selfMailerProfile: optional string` The ID of the self-mailer profile used for this campaign, if applicable. - `sendDate: optional string` The scheduled date and time for the campaign to be sent. ### Returns - `Campaign = object { id, createdAt, createdCount, 15 more }` Represents a bulk mail campaign. - `id: string` A unique ID prefixed with campaign_ - `createdAt: string` The UTC time at which this resource was created. - `createdCount: number` The number of orders successfully created for this campaign. - `live: boolean` `true` if this is a live mode resource else `false`. - `mailingList: string` The ID of the mailing list associated with this campaign. - `status: "drafting" or "changes_required" or "creating_orders" or 4 more` Status of the campaign lifecycle. - `"drafting"` - `"changes_required"` - `"creating_orders"` - `"draft"` - `"ready"` - `"printing"` - `"processed_for_delivery"` - `updatedAt: string` The UTC time at which this resource was last updated. - `chequeProfile: optional string` The ID of the cheque profile used for this campaign, if applicable. - `defaultSenderContact: optional string` The ID of the default sender contact to use for orders if not specified per recipient. - `description: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `errors: optional array of object { message, type }` A list of processing errors encountered, if any. Present when status is 'changes_required'. - `message: string` A human-readable message describing the error. - `type: "processing_error" or "internal_error"` Type of error encountered during campaign processing. - `"processing_error"` - `"internal_error"` - `letterProfile: optional string` The ID of the letter profile used for this campaign, if applicable. - `metadata: optional map[unknown]` See the section on Metadata. - `orderPreviewURL: optional string` A temporary URL to preview the first rendered order, available once the campaign status is 'draft' or later. - `postcardProfile: optional string` The ID of the postcard profile used for this campaign, if applicable. - `reportURL: optional string` A temporary URL to download the processing report, available once the campaign is in the `ready` status. - `selfMailerProfile: optional string` The ID of the self-mailer profile used for this campaign, if applicable. - `sendDate: optional string` The scheduled date and time for the campaign to be sent. ### Example ```http curl https://api.postgrid.com/print-mail/v1/campaigns \ -H 'Content-Type: application/json' \ -H "X-API-Key: $POSTGRID_PRINT_MAIL_API_KEY" \ -d '{ "mailingList": "mailingList" }' ``` #### 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 **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. ### Query Parameters - `limit: optional number` - `search: optional string` 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 number` ### Returns - `data: array of Campaign` - `id: string` A unique ID prefixed with campaign_ - `createdAt: string` The UTC time at which this resource was created. - `createdCount: number` The number of orders successfully created for this campaign. - `live: boolean` `true` if this is a live mode resource else `false`. - `mailingList: string` The ID of the mailing list associated with this campaign. - `status: "drafting" or "changes_required" or "creating_orders" or 4 more` Status of the campaign lifecycle. - `"drafting"` - `"changes_required"` - `"creating_orders"` - `"draft"` - `"ready"` - `"printing"` - `"processed_for_delivery"` - `updatedAt: string` The UTC time at which this resource was last updated. - `chequeProfile: optional string` The ID of the cheque profile used for this campaign, if applicable. - `defaultSenderContact: optional string` The ID of the default sender contact to use for orders if not specified per recipient. - `description: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `errors: optional array of object { message, type }` A list of processing errors encountered, if any. Present when status is 'changes_required'. - `message: string` A human-readable message describing the error. - `type: "processing_error" or "internal_error"` Type of error encountered during campaign processing. - `"processing_error"` - `"internal_error"` - `letterProfile: optional string` The ID of the letter profile used for this campaign, if applicable. - `metadata: optional map[unknown]` See the section on Metadata. - `orderPreviewURL: optional string` A temporary URL to preview the first rendered order, available once the campaign status is 'draft' or later. - `postcardProfile: optional string` The ID of the postcard profile used for this campaign, if applicable. - `reportURL: optional string` A temporary URL to download the processing report, available once the campaign is in the `ready` status. - `selfMailerProfile: optional string` The ID of the self-mailer profile used for this campaign, if applicable. - `sendDate: optional string` The scheduled date and time for the campaign to be sent. - `limit: number` - `object: "list"` - `"list"` - `skip: number` - `totalCount: number` ### Example ```http curl https://api.postgrid.com/print-mail/v1/campaigns \ -H "X-API-Key: $POSTGRID_PRINT_MAIL_API_KEY" ``` #### 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 **get** `/print-mail/v1/campaigns/{id}` Retrieve a specific campaign by its ID. ### Path Parameters - `id: string` ### Returns - `Campaign = object { id, createdAt, createdCount, 15 more }` Represents a bulk mail campaign. - `id: string` A unique ID prefixed with campaign_ - `createdAt: string` The UTC time at which this resource was created. - `createdCount: number` The number of orders successfully created for this campaign. - `live: boolean` `true` if this is a live mode resource else `false`. - `mailingList: string` The ID of the mailing list associated with this campaign. - `status: "drafting" or "changes_required" or "creating_orders" or 4 more` Status of the campaign lifecycle. - `"drafting"` - `"changes_required"` - `"creating_orders"` - `"draft"` - `"ready"` - `"printing"` - `"processed_for_delivery"` - `updatedAt: string` The UTC time at which this resource was last updated. - `chequeProfile: optional string` The ID of the cheque profile used for this campaign, if applicable. - `defaultSenderContact: optional string` The ID of the default sender contact to use for orders if not specified per recipient. - `description: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `errors: optional array of object { message, type }` A list of processing errors encountered, if any. Present when status is 'changes_required'. - `message: string` A human-readable message describing the error. - `type: "processing_error" or "internal_error"` Type of error encountered during campaign processing. - `"processing_error"` - `"internal_error"` - `letterProfile: optional string` The ID of the letter profile used for this campaign, if applicable. - `metadata: optional map[unknown]` See the section on Metadata. - `orderPreviewURL: optional string` A temporary URL to preview the first rendered order, available once the campaign status is 'draft' or later. - `postcardProfile: optional string` The ID of the postcard profile used for this campaign, if applicable. - `reportURL: optional string` A temporary URL to download the processing report, available once the campaign is in the `ready` status. - `selfMailerProfile: optional string` The ID of the self-mailer profile used for this campaign, if applicable. - `sendDate: optional string` The scheduled date and time for the campaign to be sent. ### Example ```http curl https://api.postgrid.com/print-mail/v1/campaigns/$ID \ -H "X-API-Key: $POSTGRID_PRINT_MAIL_API_KEY" ``` #### 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 **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`. ### Path Parameters - `id: string` ### Body Parameters - `chequeProfile: optional string` The ID of the cheque profile to use. Setting this will remove other profile types. Set to `null` to remove. - `defaultSenderContact: optional string` The ID of the default sender contact. Set to `null` to remove. - `description: optional string` An optional description for the campaign. Set to `null` to remove the existing description. - `letterProfile: optional string` The ID of the letter profile to use. Setting this will remove other profile types. Set to `null` to remove. - `mailingList: optional string` The ID of the mailing list to associate with this campaign. - `metadata: optional map[string]` Optional key-value data associated with the campaign. Set to `null` to remove existing metadata. - `postcardProfile: optional string` The ID of the postcard profile to use. Setting this will remove other profile types. Set to `null` to remove. - `selfMailerProfile: optional string` The ID of the self-mailer profile to use. Setting this will remove other profile types. Set to `null` to remove. ### Returns - `Campaign = object { id, createdAt, createdCount, 15 more }` Represents a bulk mail campaign. - `id: string` A unique ID prefixed with campaign_ - `createdAt: string` The UTC time at which this resource was created. - `createdCount: number` The number of orders successfully created for this campaign. - `live: boolean` `true` if this is a live mode resource else `false`. - `mailingList: string` The ID of the mailing list associated with this campaign. - `status: "drafting" or "changes_required" or "creating_orders" or 4 more` Status of the campaign lifecycle. - `"drafting"` - `"changes_required"` - `"creating_orders"` - `"draft"` - `"ready"` - `"printing"` - `"processed_for_delivery"` - `updatedAt: string` The UTC time at which this resource was last updated. - `chequeProfile: optional string` The ID of the cheque profile used for this campaign, if applicable. - `defaultSenderContact: optional string` The ID of the default sender contact to use for orders if not specified per recipient. - `description: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `errors: optional array of object { message, type }` A list of processing errors encountered, if any. Present when status is 'changes_required'. - `message: string` A human-readable message describing the error. - `type: "processing_error" or "internal_error"` Type of error encountered during campaign processing. - `"processing_error"` - `"internal_error"` - `letterProfile: optional string` The ID of the letter profile used for this campaign, if applicable. - `metadata: optional map[unknown]` See the section on Metadata. - `orderPreviewURL: optional string` A temporary URL to preview the first rendered order, available once the campaign status is 'draft' or later. - `postcardProfile: optional string` The ID of the postcard profile used for this campaign, if applicable. - `reportURL: optional string` A temporary URL to download the processing report, available once the campaign is in the `ready` status. - `selfMailerProfile: optional string` The ID of the self-mailer profile used for this campaign, if applicable. - `sendDate: optional string` The scheduled date and time for the campaign to be sent. ### Example ```http curl https://api.postgrid.com/print-mail/v1/campaigns/$ID \ -H 'Content-Type: application/json' \ -H "X-API-Key: $POSTGRID_PRINT_MAIL_API_KEY" \ -d '{}' ``` #### 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 **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. ### Path Parameters - `id: string` ### Returns - `id: string` A unique ID prefixed with campaign_ - `deleted: true` - `true` ### Example ```http curl https://api.postgrid.com/print-mail/v1/campaigns/$ID \ -X DELETE \ -H "X-API-Key: $POSTGRID_PRINT_MAIL_API_KEY" ``` #### Response ```json { "id": "campaign_sqF12lZ1VlBb", "deleted": true } ``` ## Send 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. ### Path Parameters - `id: string` ### Body Parameters - `sendDate: optional string or string` The date and time the campaign should be sent. Must be in the future. If omitted, defaults to the earliest possible processing date. - `string` - `string` ### Returns - `Campaign = object { id, createdAt, createdCount, 15 more }` Represents a bulk mail campaign. - `id: string` A unique ID prefixed with campaign_ - `createdAt: string` The UTC time at which this resource was created. - `createdCount: number` The number of orders successfully created for this campaign. - `live: boolean` `true` if this is a live mode resource else `false`. - `mailingList: string` The ID of the mailing list associated with this campaign. - `status: "drafting" or "changes_required" or "creating_orders" or 4 more` Status of the campaign lifecycle. - `"drafting"` - `"changes_required"` - `"creating_orders"` - `"draft"` - `"ready"` - `"printing"` - `"processed_for_delivery"` - `updatedAt: string` The UTC time at which this resource was last updated. - `chequeProfile: optional string` The ID of the cheque profile used for this campaign, if applicable. - `defaultSenderContact: optional string` The ID of the default sender contact to use for orders if not specified per recipient. - `description: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `errors: optional array of object { message, type }` A list of processing errors encountered, if any. Present when status is 'changes_required'. - `message: string` A human-readable message describing the error. - `type: "processing_error" or "internal_error"` Type of error encountered during campaign processing. - `"processing_error"` - `"internal_error"` - `letterProfile: optional string` The ID of the letter profile used for this campaign, if applicable. - `metadata: optional map[unknown]` See the section on Metadata. - `orderPreviewURL: optional string` A temporary URL to preview the first rendered order, available once the campaign status is 'draft' or later. - `postcardProfile: optional string` The ID of the postcard profile used for this campaign, if applicable. - `reportURL: optional string` A temporary URL to download the processing report, available once the campaign is in the `ready` status. - `selfMailerProfile: optional string` The ID of the self-mailer profile used for this campaign, if applicable. - `sendDate: optional string` The scheduled date and time for the campaign to be sent. ### Example ```http curl https://api.postgrid.com/print-mail/v1/campaigns/$ID/send \ -H 'Content-Type: application/json' \ -H "X-API-Key: $POSTGRID_PRINT_MAIL_API_KEY" \ -d '{}' ``` #### 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 - `Campaign = object { id, createdAt, createdCount, 15 more }` Represents a bulk mail campaign. - `id: string` A unique ID prefixed with campaign_ - `createdAt: string` The UTC time at which this resource was created. - `createdCount: number` The number of orders successfully created for this campaign. - `live: boolean` `true` if this is a live mode resource else `false`. - `mailingList: string` The ID of the mailing list associated with this campaign. - `status: "drafting" or "changes_required" or "creating_orders" or 4 more` Status of the campaign lifecycle. - `"drafting"` - `"changes_required"` - `"creating_orders"` - `"draft"` - `"ready"` - `"printing"` - `"processed_for_delivery"` - `updatedAt: string` The UTC time at which this resource was last updated. - `chequeProfile: optional string` The ID of the cheque profile used for this campaign, if applicable. - `defaultSenderContact: optional string` The ID of the default sender contact to use for orders if not specified per recipient. - `description: optional string` An optional string describing this resource. Will be visible in the API and the dashboard. - `errors: optional array of object { message, type }` A list of processing errors encountered, if any. Present when status is 'changes_required'. - `message: string` A human-readable message describing the error. - `type: "processing_error" or "internal_error"` Type of error encountered during campaign processing. - `"processing_error"` - `"internal_error"` - `letterProfile: optional string` The ID of the letter profile used for this campaign, if applicable. - `metadata: optional map[unknown]` See the section on Metadata. - `orderPreviewURL: optional string` A temporary URL to preview the first rendered order, available once the campaign status is 'draft' or later. - `postcardProfile: optional string` The ID of the postcard profile used for this campaign, if applicable. - `reportURL: optional string` A temporary URL to download the processing report, available once the campaign is in the `ready` status. - `selfMailerProfile: optional string` The ID of the self-mailer profile used for this campaign, if applicable. - `sendDate: optional string` The scheduled date and time for the campaign to be sent.