c2mAPIBatch Object

The c2mAPIBatch object encapsulates the basic functionality needed to execute batch 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
batchIDstringID of the batch created with this instance
jobIdstringUnused
addressListIdstringID of the address list associated with this batch
documentIDstringUnused
modestring ("0" or "1")"0" : run in staging / testing environment
"1" : run in production environment
usernamestringAccount user name
passwordstringAccount password
jobslist of listsList of lists of key : value pairs with information for each job. Each list is of the form:
{ "startPage":startPage, "endPage":endPage, "printOptions":printOptions, "returnAddress":returnAddress, "recipients":recipients }

Object Methods

addJob() Method

This method adds a job to the batch by appending the job information to .jobs.

It does not return any value.

ParameterTypeDescription
startPagestringStarting page
endPagestringEnding page
printOptionsc2mAPI.printOptionsObject containing the list of print options for the job
returnAddressc2mAPI.returnAddressObject containing the return address for the job
recipientslist of listsA list of lists containing the addresses for the job to be sent to. Each address list is of the form:
{'name':'name', 'organization':'organization', 'address1':'1235 test street', 'address2':'ste 1234', 'address3':'', 'city':'Oak Brook', 'state':'IL', 'postalCode':'60523', 'country':'US'}

createBatch() Method

This method creates the batch to be processed and sets .batchID to the value of the batch ID created.

Returns the requests.Response() object resulting from the POST call to the /batches endpoint.


createBatchXML() Method

This method builds out the required XML needed to run the batch job.

Returns the constructed XML as a string.


getBatchStatus() Method

This method queries the system for the current status of .batchID.

Returns the requests.Response() object resulting from the GET call to the /batches endpoint.


getBatchUrl() Method

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


runAll() Method

This method executes all the necessary methods to create a new batch, upload the PDF file, build and submit the configuration XML, and submit the batch.

On success, returns the requests.Response() object resulting from the GET call to the /batches endpoint (based on an internal call to getBatchStatus().

On a failure of any step, returns the requests.Response() object associated with the failed step.


sendPDF() Method

This method uploads the PDF file to be referenced in the batch job.

Returns the requests.Response() object resulting from the PUT call to the /batches endpoint.

ParameterTypeDescription
filestringThe pdf file to send

sendXML() Method

This method uploads the batch configuration XML for the .batchID batch.

Returns the requests.Response() object resulting from the PUT call to the /batches endpoint.

ParameterTypeDescription
xmlStrstringThe XML string to send

setFileName() Method

This method sets the properties .fileName and .filePath.

There is no return value

ParameterTypeDescription
fileNamestringThe name of the file
filePathstringThe path to the file on the local filesystem

submitBatch() Method

This method submits batch .batchID for execution.

Returns the requests.Response() object resulting from the POST call to the /batches endpoint.