Our v3 API is now available! Learn more by visiting the v3 developer portal. Creating new v2 API keys is no longer supported.

Add Library Files - Multipart POST

Use this endpoint to add files to the Library using the multipart content-type.


Click a method to view its documentation



Privileges required: mylibrary:file:create

The POST method adds a file to a Library folder using the multipart form content-type. If there are no folders in the account, set folder_id = 0.

NOTE: Set the Content-Type header to multipart/form-data.

Supported File Types

The currently supported file types you can add using POST are:

  • Image files - JPEG, JPG, GIF, PNG
  • Document files - PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX

Required Multipart Elements

The multipart request needs to include the parts defined in the Structure section.

Java Example - Multipart Encoded POST

Here's an example of a multipart encoded post in Java that uploads an image file (dinnerplate-special.jpg) to a user's Library:

import java.io.File;
import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class Test {
       /** * @param args
        * @throws IOException
        * @throws ClientProtocolException
       public static void main(String[] args) throws ClientProtocolException, IOException {

              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost("https://api.constantcontact.com/v2/library/files");

              httppost.addHeader("Authorization", "Bearer 70e8e17d-e1ed-4b7a-8a8a-40383d74d467");
              httppost.addHeader("Accept", "application/json");
              httppost.addHeader("Content-type", "multipart/form-data");

              File fileToUse = new File("/path_to_file/YOLO.jpg"); //e.g. /temp/dinnerplate-special.jpg
              FileBody data = new FileBody(fileToUse);

              String file_type = "JPG" ;
              String description = "Oppa Gangnam Style";
              String folder_id = "-1";
              String source = "MYCOMPUTER" ;

              MultipartEntity reqEntity = new MultipartEntity();
              reqEntity.addPart("file_name", new StringBody( fileToUse.getName() ) );
              reqEntity.addPart("folder_id", new StringBody(folder_id));
              reqEntity.addPart("description", new StringBody(description));
              reqEntity.addPart("source", new StringBody(source));
              reqEntity.addPart("file_type", new StringBody(file_type));
              reqEntity.addPart("data", data);


             HttpResponse response = httpclient.execute(httppost);
             System.out.println( response ) ;

             HttpEntity resEntity = response.getEntity();
             System.out.println( resEntity ) ;
              System.out.println( EntityUtils.toString(resEntity) );


Ruby Example - Multipart Encoded POST

See an example coded in Ruby in our Github repository.

POST Status

The API performs multiple operations in order to POST a file, including performing a virus scan, so processing the POST can take a certain amount of time. You can monitor the request status using the location value in the response header.

See File Upload Status for more information.


Privileges required: contacts:write

You can remove contacts from one or more contact lists using a .txt or .csv file that contains only the email addresses of the contacts to be removed. You need to use an HTTP multipart request in a POST to this endpoint. The multipart request contains three parameters: file_name, lists, and data, defined in the Structure section below.


The size of the payload (import file) must be less than 4 megabytes. Also, you can remove a maximum of 20,000 contacts in a single POST. The activity will fail if the payload is greater than 4 MBs or if it includes more than 20,000 contacts.

The data file must contain only email addresses. Do not include any other data columns in the file, and do not include any labels or other non-email content in the file.

Example Multipart Encoded POST

The following is an example multipart encoded post written in Java that removes contacts from contact lists 4 and 6 by importing a file (contacts.txt) containing only the email addresses of the contacts to remove:

final HttpClient httpclient = new DefaultHttpClient();
   final HttpPost httppost = new HttpPost("https://api.constantcontact.com/v2/activities/removefromlists");

   httppost.addHeader("Authorization", "Bearer 5e35af38-7b63-47cac-b484-20c4ff4d09c8");
   httppost.addHeader("Accept", ”application/json”);
   httppost.addHeader("content-type", "multipart/form-data");

   final File fileToUse = new File("/path_to_file/contacts.txt");   //e.g. /temp/contact.txt
   final FileBody data = new FileBody(fileToUse);
   final String listIds = "1", "4";
   final StringBody lists = new StringBody(listIds);
   final StringBody fileName = new StringBody(fileToUse.getName());
   final MultipartEntity reqEntity = new MultipartEntity();
   reqEntity.addPart("file_name", fileName);
   reqEntity.addPart("lists", lists);
   reqEntity.addPart("data", data);


   final HttpResponse response = httpclient.execute(httppost);
   final HttpEntity resEntity = response.getEntity();



Activity Status

To see the status of an activity, make a GET call to the URI returned in the response's location header:

Location: https://api.constantcontact.com/v2/activities/<activity_id>

Poll this URI to monitor the activity status until the status is either COMPLETE or ERROR, indicating that the activity has completed processing. The response structure for this GET call is detailed here.

See also: Summary Activity Reports API 


Privileges required: mylibrary:folder:create

Create a new MyLibrary folder by providing the name of the folder and the id of the parent folder if the new folder is to be a child folder (nested in another folder) in the JSON request body. See the example JSON request in the following sections.

POST: https://api.constantcontact.com/v2/library/files

Test API







REQUIRED; The API key for the application

Response CodesTOP




Library file was successfully created


Either JSON was malformed or there was a data validation error


Authentication failure


Internal server error occurred



type(max length)