Create Letter Create Letter
print_mail.letters.create(LetterCreateParams**kwargs) -> LetterCreateResponse
POST/print-mail/v1/letters
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
description: Optional[str]
An optional string describing this resource. Will be visible in the API and the dashboard.
envelope: Optional[str]
The envelope (ID) for the letter. You can either specify a custom envelope ID or use the default standard envelope.
merge_variables: Optional[Dict[str, object]]
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.
perforated_page: Optional[Literal[1]]
If specified, indicates which letter page is perforated. Currently, only the first page can be perforated.
Create Letter 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(
from_="contact_123",
html="<html>Content</html>",
to="contact_123",
paper="standard",
)
print(letter){
"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",
"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",
"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",
"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",
"template": "template",
"trackingNumber": "trackingNumber",
"uploadedPDF": "https://example.com",
"url": "https://example.com"
}