Perform batch operations

If you're performing several operations, the time it takes to send and receive all those HTTP messages can make your app slow and unresponsive. With batch requests, you can have the server perform multiple operations with a single HTTP request. The basic idea is that you create a contacts feed and add an entry for each operation that you want to perform.

Batch requests are limited to 100 operations at a time. You can find more information about batch operations in Batch Processing in the Google Data Protocol. Changes can take up to 24 hours to be reflected in the email address autocomplete and the contact manager.

The following code sample shows a batch request that creates 2 shared contacts; however, you can also use a batch request to query, update, and delete contacts. The update and delete entries require an edit link for optimistic concurrency to work.

<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom'
      xmlns:gContact='http://schemas.google.com/contact/2008'
      xmlns:gd='http://schemas.google.com/g/2005'
      xmlns:batch='http://schemas.google.com/gdata/batch'>
  <category scheme='http://schemas.google.com/g/2005#kind'
      term='http://schemas.google.com/g/2008#contact' />
  <entry>
    <batch:id>1</batch:id>
    <batch:operation type='insert' />
    <category scheme='http://schemas.google.com/g/2005#kind'
      term='http://schemas.google.com/g/2008#contact'/>
    <gd:name>
      <gd:givenName>FIRST_NAME</gd:fullName>
      <gd:familyName>LAST_NAME</gd:fullName>
    </gd:name>
    <gd:email rel='http://schemas.google.com/g/2005#home'
      address='EMAIL_ADDRESS' primary='true'/>
  </entry>
  <entry>
    <batch:id>2</batch:id>
    <batch:operation type='insert' />
    <category scheme='http://schemas.google.com/g/2005#kind'
      term='http://schemas.google.com/g/2008#contact'/>
    <gd:name>
      <gd:givenName>FIRST_NAME</gd:fullName>
      <gd:familyName>LAST_NAME</gd:fullName>
    </gd:name>
    <gd:email rel='http://schemas.google.com/g/2005#home'
      address='EMAIL_ADDRESS'
      primary='true'/>
  </entry>
</feed>

Replace the following:

  • FIRST_NAME: First name of the shared contact—for example, Alex.
  • LAST_NAME: The last name of the shared contact—for example, Kim.
  • EMAIL_ADDRESS: The preferred email address of the shared contact—for example, alk@gmail.com.