REST API:bulk Resource

From AgileApps Support Wiki

Jump to: navigation, search

Provides Data Import capabilities using the REST API. Using this API, a CSV file containing data records can be uploaded to an object.

Learn more:
See also:



Bulk Upload Object Data

Loads CSV data into an object.

objectName: An Object Identifier. Object names are recommended, but Object IDs are supported for backward compatibility.
All Custom Objects support bulk upload.


Note: Specify the Object Name in the URI. Case is significant.

A multipart request with file part for the CSV data and an XML part with information.
Here's a sample request that uploads data to a Customers object:
Content-Type: multipart/form-data; boundary=.............................103832778631715

Content-Disposition: form-data; name="bulk";
Content-Type: application/xml;


Content-Disposition: form-data; name="Customers.csv"; filename="Customers.csv"
Content-type: application/octet-stream

{contents of file}
Learn more: REST API:Multipart Request

Returns the id of the submitted import job, along with a message telling whether or not the job was accepted for processing. (Use the REST import Status resource to follow the progress of the job.)

        <id>yur456poi967</id>      <!-- import process job ID -->  
See also: REST API:Error Codes


Name Type Required Description
mapping String Yes Name of the Mapping Profile created in the platform UI

Sample Http Client for bulk uploads

This sample client uploads Customer data. It is contained in the Samples Zip file.
(For the JAR files it uses, see Setting Up the Development Enviroment.)
Learn more about the login process: REST login resource


import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

import org.w3c.dom.Document;
import org.xml.sax.InputSource;

public class BulkUploadClient {
  public static void main(String[] args)
      // Modify the login() method to specify user name and password.
      HttpClient httpClient = login();

      String url = "http://localhost/networking/rest/bulk/Customer";      
      String importXml =
        "<platform>" +
           "<bulk>" +
              "<mapping>CustomerMap</mapping>" +                              
           "</bulk>" +
        "</platform>" ;
      // XML part
      StringPart sp = new StringPart("bulk", importXml);
      // File part
      File file = new File("c:/document/customers.csv");    
      // Multipart wrapper
      Part[] part = {                        
                      new FilePart(file.getName(),file),
      // Create the request          
      PostMethod postMethod = new PostMethod(url);
      MultipartRequestEntity requestEntity =
          new MultipartRequestEntity( part, postMethod.getParams() );

      // Send it
      int status  = httpClient.executeMethod(postMethod);  
      System.out.println("HTTP Status = " + status);            
      String responseXml = postMethod.getResponseBodyAsString();
      String jobId = getValue("platform/message/id", responseXml);

      System.out.println("Use the following URL to check job status:");
                       + jobId);          
      catch (Exception e)
   * Log into the platform. After doing so, session ID is automatically
   * set for all future requests that use the HttpClient. (The server sets up
   * a cookie string for the session, and returns it in the response. The
   * HttpClient instance saves that string and adds it to subsequent requests.
   * Reusing an instance of HttpClient, in effect, defines a "session".)
   * @return The HttpClient object when the login succeeds.
   * @throws An exception if the login fails.

  public static HttpClient login() throws Exception
      String url = "https://{{domain}}/networking/rest/login";
      PostMethod postMethod = new PostMethod(url);      
      String loginXml =
            "<platform>" +
               "<login>" +
                  "<userName>yourLoginName</userName>" +
                  "<password>YourPassword</password>" +
               "</login>" +
            "</platform>" ;
      StringRequestEntity reqXml =
        new StringRequestEntity(loginXml, MediaType.APPLICATION_XML, "UTF-8");
      // Log in
      HttpClient httpClient = new HttpClient();      
      int status = httpClient.executeMethod(postMethod);
      if (status != 200) {
         throw new Exception("Login failed with HTTP status " + status);
      return httpClient;

   * Given an XPath expression and XML, parse for a specific value.
   * @param xpath_expr  An XPATH expression.
   *                    For example: "/platform/message/description"
   * @param xml The XML string to be parsed.

  public static String getValue(String xpath_expr, String xml)
    try {
      DocumentBuilderFactory docFactory =
      DocumentBuilder docbuilder = docFactory.newDocumentBuilder();
      InputStream is = new ByteArrayInputStream(xml.getBytes());

      Document doc = docbuilder.parse(new InputSource(is));
      XPathFactory factory = XPathFactory.newInstance();
      XPath xpath = factory.newXPath();
      XPathExpression expr = xpath.compile(xpath_expr);
      Object result = expr.evaluate(doc, XPathConstants.STRING);
      return result.toString();
    catch (Exception e)
    return null;
Personal tools