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

Property

Type

Description

addressList

List of {'key' : 'value'} pairs

The 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

addressListId

string

ID of the address list returned after creation

addressMappingId

string

Address list format mapping style to be used. 1 and 2 are provided as defaults. Custom ones can be created. See the addressList property above

batchID

string

ID of the batch returned after creation

documentId

string

ID of the document returned after creation

jobId

string

ID of the job returned after creation

mode

string ("0" or "1")

"0" : run in staging / testing environment
"1" : run in production environment

password

string

Account password

username

string

Account 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.

Parameter

Type

Description

addressMappingId

string

Address 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.

Parameter

Type

Description

fileName

string

Path 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.

Parameter

Type

Description

document1Id

string

The ID of the first document to merge

document2Id

string

The 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.

Parameter

Type

Description

fileName

string

Path and file name of the PDF file to be uploaded

documentName

string

The name of the document to be created in the account

documentClass

string

The size and type of the printed document. E.g., Letter 8.5 x 11

documentFormat

string

The 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.

Parameter

Type

Description

printOptions

c2mAPIRest.printOptions

Object 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.

Parameter

Type

Description

templateName

string

The 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.

Parameter

Type

Description

document1Id

string

The ID of the first document to merge

document2Id

string

The ID of the second document to merge

documentName

string

The 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()

Parameter

Type

Description

fileName

string

Name of file on the local filesystem to be uploaded

addressMappingId

string

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

printOptions

c2mAPI.printOptions

Object 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()

Parameter

Type

Description

fileNameSide1

string

Name of file on the local filesystem containing side one of the document be uploaded

fileNameSide2

string

Name of file on the local filesystem containing side two of the document be uploaded

documentName

string

The name of the document to be created in the account

documentClass

string

The size and type of the printed document. E.g., Letter 8.5 x 11

documentFormat

string

The file format of the document being uploaded. PDF is most common, but numerous others are supported as well

addressMappingId

string

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

printOptions

c2mAPI.printOptions

Object 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()

Parameter

Type

Description

fileName

string

Name of file on the local filesystem to be uploaded

addressMappingId

string

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

templateName

string

The 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.