Create Letter
Create a letter. Note that you can supply one of the following:
- HTML content for the letter
- A template ID for the letter
- A URL for a PDF for the letter Create a letter via a multipart/form-data request. Accepts the same
fields as the JSON create body (nested objects are bracket-encoded form
fields, e.g.
to[firstName]); use this content type to upload the PDF file directly.
Parameters
An optional string describing this resource. Will be visible in the API and the dashboard.
The envelope (ID) for the letter. You can either specify a custom envelope ID or use the default standard envelope.
These will be merged with the variables in the template or HTML you create this order with. The keys in this object should match the variable names in the template exactly as they are case-sensitive. Note that these do not apply to PDFs uploaded with the order.
If specified, indicates which letter page is perforated. Currently, only the first page can be perforated.
Use a virtual mailbox as the return address instead of a sender contact. Supply an array with exactly one virtual mailbox ID, e.g. ["virtual_mailbox_abcdefg123456890"]; PostGrid generates the return address from the physical mailbox assigned to it, and returned mail shows up as items of that virtual mailbox. Cannot be combined with from or postageDiscountAuthorization.
Create Letter
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
)
letter = client.print_mail.letters.create(
html="<html>Content</html>",
to="contact_123",
from_="contact_123",
paper="standard",
)
print(letter.id){
"id": "letter_sqF12lZ1VlBb",
"addressPlacement": "top_first_page",
"color": true,
"createdAt": "2019-12-27T18:11:19.117Z",
"doubleSided": true,
"envelope": "envelope",
"from": {
"id": "contact_sqF12lZ1VlBb",
"addressLine1": "addressLine1",
"addressStatus": "verified",
"countryCode": "countryCode",
"createdAt": "2019-12-27T18:11:19.117Z",
"live": true,
"object": "contact",
"updatedAt": "2019-12-27T18:11:19.117Z",
"addressErrors": "addressErrors",
"addressLine2": "addressLine2",
"city": "city",
"companyName": "companyName",
"description": "description",
"email": "email",
"firstName": "firstName",
"forceVerifiedStatus": true,
"jobTitle": "jobTitle",
"lastName": "lastName",
"metadata": {
"foo": "bar"
},
"phoneNumber": "phoneNumber",
"postalOrZip": "postalOrZip",
"provinceOrState": "provinceOrState",
"secret": true,
"skipVerification": true
},
"live": true,
"mailingClass": "first_class",
"object": "letter",
"sendDate": "2019-12-27T18:11:19.117Z",
"size": "us_letter",
"status": "ready",
"to": {
"id": "contact_sqF12lZ1VlBb",
"addressLine1": "addressLine1",
"addressStatus": "verified",
"countryCode": "countryCode",
"createdAt": "2019-12-27T18:11:19.117Z",
"live": true,
"object": "contact",
"updatedAt": "2019-12-27T18:11:19.117Z",
"addressErrors": "addressErrors",
"addressLine2": "addressLine2",
"city": "city",
"companyName": "companyName",
"description": "description",
"email": "email",
"firstName": "firstName",
"forceVerifiedStatus": true,
"jobTitle": "jobTitle",
"lastName": "lastName",
"metadata": {
"foo": "bar"
},
"phoneNumber": "phoneNumber",
"postalOrZip": "postalOrZip",
"provinceOrState": "provinceOrState",
"secret": true,
"skipVerification": true
},
"updatedAt": "2019-12-27T18:11:19.117Z",
"attachedPDF": {
"file": "https://example.com",
"placement": "before_template"
},
"cancellation": {
"reason": "user_initiated",
"cancelledByUser": "cancelledByUser",
"note": "note"
},
"description": "description",
"html": "html",
"imbDate": "2019-12-27T18:11:19.117Z",
"imbEvents": [
{
"date": "2019-12-27T18:11:19.117Z",
"status": "entered_mail_stream",
"zipCode": "zipCode",
"scanCode": "scanCode"
}
],
"imbStatus": "entered_mail_stream",
"imbZIPCode": "imbZIPCode",
"mergeVariables": {
"foo": "bar"
},
"metadata": {
"foo": "bar"
},
"paper": "standard",
"pdfWorkflowRun": "pdfWorkflowRun",
"perforatedPage": 1,
"plasticCard": {
"size": "standard",
"doubleSided": {
"backHTML": "backHTML",
"backTemplate": "backTemplate",
"frontHTML": "frontHTML",
"frontTemplate": "frontTemplate",
"pdf": "https://example.com"
},
"singleSided": {
"html": "html",
"pdf": "https://example.com",
"template": "template"
}
},
"returnEnvelope": "returnEnvelope",
"statusEvents": [
{
"date": "2019-12-27T18:11:19.117Z",
"status": "ready"
}
],
"template": "template",
"trackingNumber": "trackingNumber",
"uploadedPDF": "https://example.com",
"url": "https://example.com"
}Returns Examples
{
"id": "letter_sqF12lZ1VlBb",
"addressPlacement": "top_first_page",
"color": true,
"createdAt": "2019-12-27T18:11:19.117Z",
"doubleSided": true,
"envelope": "envelope",
"from": {
"id": "contact_sqF12lZ1VlBb",
"addressLine1": "addressLine1",
"addressStatus": "verified",
"countryCode": "countryCode",
"createdAt": "2019-12-27T18:11:19.117Z",
"live": true,
"object": "contact",
"updatedAt": "2019-12-27T18:11:19.117Z",
"addressErrors": "addressErrors",
"addressLine2": "addressLine2",
"city": "city",
"companyName": "companyName",
"description": "description",
"email": "email",
"firstName": "firstName",
"forceVerifiedStatus": true,
"jobTitle": "jobTitle",
"lastName": "lastName",
"metadata": {
"foo": "bar"
},
"phoneNumber": "phoneNumber",
"postalOrZip": "postalOrZip",
"provinceOrState": "provinceOrState",
"secret": true,
"skipVerification": true
},
"live": true,
"mailingClass": "first_class",
"object": "letter",
"sendDate": "2019-12-27T18:11:19.117Z",
"size": "us_letter",
"status": "ready",
"to": {
"id": "contact_sqF12lZ1VlBb",
"addressLine1": "addressLine1",
"addressStatus": "verified",
"countryCode": "countryCode",
"createdAt": "2019-12-27T18:11:19.117Z",
"live": true,
"object": "contact",
"updatedAt": "2019-12-27T18:11:19.117Z",
"addressErrors": "addressErrors",
"addressLine2": "addressLine2",
"city": "city",
"companyName": "companyName",
"description": "description",
"email": "email",
"firstName": "firstName",
"forceVerifiedStatus": true,
"jobTitle": "jobTitle",
"lastName": "lastName",
"metadata": {
"foo": "bar"
},
"phoneNumber": "phoneNumber",
"postalOrZip": "postalOrZip",
"provinceOrState": "provinceOrState",
"secret": true,
"skipVerification": true
},
"updatedAt": "2019-12-27T18:11:19.117Z",
"attachedPDF": {
"file": "https://example.com",
"placement": "before_template"
},
"cancellation": {
"reason": "user_initiated",
"cancelledByUser": "cancelledByUser",
"note": "note"
},
"description": "description",
"html": "html",
"imbDate": "2019-12-27T18:11:19.117Z",
"imbEvents": [
{
"date": "2019-12-27T18:11:19.117Z",
"status": "entered_mail_stream",
"zipCode": "zipCode",
"scanCode": "scanCode"
}
],
"imbStatus": "entered_mail_stream",
"imbZIPCode": "imbZIPCode",
"mergeVariables": {
"foo": "bar"
},
"metadata": {
"foo": "bar"
},
"paper": "standard",
"pdfWorkflowRun": "pdfWorkflowRun",
"perforatedPage": 1,
"plasticCard": {
"size": "standard",
"doubleSided": {
"backHTML": "backHTML",
"backTemplate": "backTemplate",
"frontHTML": "frontHTML",
"frontTemplate": "frontTemplate",
"pdf": "https://example.com"
},
"singleSided": {
"html": "html",
"pdf": "https://example.com",
"template": "template"
}
},
"returnEnvelope": "returnEnvelope",
"statusEvents": [
{
"date": "2019-12-27T18:11:19.117Z",
"status": "ready"
}
],
"template": "template",
"trackingNumber": "trackingNumber",
"uploadedPDF": "https://example.com",
"url": "https://example.com"
}