Upload an Address List

Now that we have a document uploaded, it's time to tell the API where you want to send it. This is done using a POST call to the /addressLists endpoint.

Addresses in Click2Mail are contained within Address Lists (also called mailing lists). An address list may consist of a single address, or an arbitrarily large number of addresses, but actions are always taken on a list as a whole. In other words, you don't select individual addresses from a list -- you define lists for the mailing job you want to do. This differs from Address Books, which will be handled later.

Calls to /addressLists differ from most other endpoint POST calls in that there is a single body parameter consisting of an XML block, rather than individual parameters.

The structure of the XML block you send varies depending on how you wish to pass address information. We provide two fairly standard formats that will work for many situations, but you can define your own as well (which is beyond the scope of this tutorial).

The format of the block is declared using the <addressMappingId> tag. Click2Mail provides IDs 1 and 2 for general usage:

Address List Formats


The example code below uses addressMappingId 1 to create a single-address address list:

# Load the HTTP requests module
import requests

# Define the endpoint to use
url = "https://stage-rest.click2mail.com/molpro/addressLists"

# Define credentials
myusername = 'awesomeuser'
mypassword = 'gReAt/PaSsWoRd123'

headers = {
    "Accept": "application/xml",
    "Content-Type": "application/xml"

# Build the XML block containing the mappingId and the 
# address information
body = (
  '<addressListName>My First List</addressListName>'
        '<Organization>Justice League</Organization>'
        '<Address1>715 S Calhounne St</Address1>'
        '<City>Terra Firma</City>'

# Make the POST call
r = requests.post(url, data=body, headers=headers, auth=(myusername, mypassword))

# Display the result - a success should return status_code 201

# Display the full XML returned.

On a successful add, the returned data should look similar to the following. Note the returned <id> value, which is the address list's ID :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <description>CASS Standardized</description>

HTTP Return Codes And Possible Statuses

HTTP ResponseStatusDescription
2000Uploaded / Created
2003CASS Standardized → this status means address list is ready for use in jobs
4009Invalid input data

HTTP Response 500. If you get a 500 response please contact Click2Mail customer support.