c2mAPIRest Object

The c2mAPIRest object encapsulates the basic functionality needed to execute simple mail jobs via the API. It maintains as object properties most of the key elements needed to access and manage a job.

Object Properties

PropertyTypeDescription
addressListList of {'key' : 'value'} pairsThe list of addresses to be mailed. Each list item consists of a set of key:value pairings. The specific keys to be used depend on the addressMappingID specified. See the Upload an Address List guide for details on default addressMappingID formats. Review steps 1-4 of Using Variable Data / Mail Merge for details on creating custom address mappings
addressListIdstringID of the address list returned after creation
addressMappingIdstringAddress list format mapping style to be used. 1 and 2 are provided as defaults. Custom ones can be created. See the addressList property above
batchIDstringID of the batch returned after creation
documentIdstringID of the document returned after creation
jobIdstringID of the job returned after creation
modestring ("0" or "1")"0" : run in staging / testing environment
"1" : run in production environment
passwordstringAccount password
usernamestringAccount user name

Object Methods

createAddressList() Method

Converts the {'key':'value'} pairs in .addressList into the XML block required by the API.

Returns the XML as a bytes string.

ParameterTypeDescription
addressMappingIdstringAddress list format mapping style to be used. See addressMappingId in object properties

createDocument() Method

Uploads a "Letter 8.5 x 11" PDF file to the account and sets the object's .documentId property to the value returned by the API. The document is named "sample Letter".

Returns the requests.Response() object resulting from the call to the API.

ParameterTypeDescription
fileNamestringPath and file name of the PDF file to be uploaded

createDocumentMergeList() Method

Builds the XML block containing two document IDs required by the API for the mergeDocuments() method.

Returns the XML as a bytes string.

ParameterTypeDescription
document1IdstringThe ID of the first document to merge
document2IdstringThe ID of the second document to merge

createDocument_v2() Method

Uploads a file to the account and sets the object's .documentId property to the value returned by the API. This method allows the upload of any file format supported by Click2Mail

Returns the requests.Response() object resulting from the call to the API.

ParameterTypeDescription
fileNamestringPath and file name of the PDF file to be uploaded
documentNamestringThe name of the document to be created in the account
documentClassstringThe size and type of the printed document. E.g., Letter 8.5 x 11
documentFormatstringThe file format of the document being uploaded. PDF is most common, but numerous others are supported as well

createJob() Method

Create a job for submission, setting the object's .jobId property to the ID newly-created job. This method requires setting the printing options manually, which has been deprecated in favor of creating and using templates from the web application. Use the createJobFromTemplate() method instead.

Returns the requests.Response() object resulting from the call to the API.

ParameterTypeDescription
printOptionsc2mAPIRest.printOptionsObject containing the list of print options for the job

createJobFromTemplate() Method

Create a job for submission, setting the object's .jobId property to the ID newly-created job. This method requires creating a template in the Web application ahead of time.

Returns the requests.Response() object resulting from the call to the API.

ParameterTypeDescription
templateNamestringThe name of the template to be used, created in the Web application

getAddressListStatus() Method

Returns the requests.Response() object for the .addressListId property. getAddressListStatus().text contains the XML with the data about the address list.


getJobStatus() Method

Returns the requests.Response() object for the .jobId property. getJobStatus().text contains the XML with the data about the job.


getRestUrl() Method

Returns the full URL for the REST API based on the environment defined by .mode'. If .mode' = 0, it returns the staging URL, otherwise it returns the production URL.


mergeDocuments() Method

Takes the IDs of two existing documents, creates a new document that merges them, and assigns the object's .documentId property the value of the new document ID.

Returns the requests.Response() object resulting from the call to the API.

ParameterTypeDescription
document1IdstringThe ID of the first document to merge
document2IdstringThe ID of the second document to merge
documentNamestringThe name of the new document to be created

runAll() Method

This method has been deprecated in favor of runAllFromJobTemplate().

This method requires creating a printOptions object containing the desired print options. It will then upload the document, process the address list, create and submit the job.

Returns the job status as defined in getJobStatus()

ParameterTypeDescription
fileNamestringName of file on the local filesystem to be uploaded
addressMappingIdstringAddress list format mapping style to be used. See addressMappingId in object properties
printOptionsc2mAPI.printOptionsObject containing the list of print options for the job

runAllDoubleSided() Method

Runs a double-sided print job, taking the individual sides as separate file names. This method requires creating a printOptions object to specify the desired print options, which is being deprecated.

Returns the job status as defined in getJobStatus()

ParameterTypeDescription
fileNameSide1stringName of file on the local filesystem containing side one of the document be uploaded
fileNameSide2stringName of file on the local filesystem containing side two of the document be uploaded
documentNamestringThe name of the document to be created in the account
documentClassstringThe size and type of the printed document. E.g., Letter 8.5 x 11
documentFormatstringThe file format of the document being uploaded. PDF is most common, but numerous others are supported as well
addressMappingIdstringAddress list format mapping style to be used. See addressMappingId in object properties
printOptionsc2mAPI.printOptionsObject containing the list of print options for the job

runAllFromJobTemplate() Method

This method will upload the file specified in the fileName parameter, create the address list being held in the .addressList property, and execute the job using the user-defined template specified by the templateName parameter.

Returns the job status as defined in getJobStatus()

ParameterTypeDescription
fileNamestringName of file on the local filesystem to be uploaded
addressMappingIdstringAddress list format mapping style to be used. See addressMappingId in object properties
templateNamestringThe name of the template created in the web interface

submitJob() Method

Submits the job identified by .jobId for processing.

Returns the requests.Response() object for the .jobId property. submitJob().text contains the XML with the data about the job.


updateJob() Method

Updates the job identified by .jobId to reference the document identified by .documentId and the address list identified by .addressListId.

Returns the requests.Response() object for the .jobId property. UpdateJob().text contains the XML with the data about the job.


uploadAddressList() Method

Creates an address list using the .createAddressList() method based on .addressMappingId and .addressList.

Sets the .addressListId property to the value returned by the creation call.

Uploads the created address list.

Returns the requests.Response() object for the .addressListId property. uploadAddressList().text contains the XML with the data about the address list.