Batch Query for Multiple Contacts

173 views
Skip to first unread message

ct

unread,
Sep 16, 2008, 11:28:35 PM9/16/08
to Google Contacts API
Is it possible to do a batch query to return multiple contacts? This
is the batch XML I'm generating to query for just one contact and it
returns with the error "Invalid entry Id/Uri".

<feed xmlns:app="http://purl.org/atom/app#" xmlns:gd="http://
schemas.google.com/g/2005" xmlns:batch="http://schemas.google.com/
gdata/batch" xmlns:gContact="http://schemas.google.com/contact/2008"
xmlns="http://www.w3.org/2005/Atom"><category term="http://
schemas.google.com/contact/2008#contact" scheme="http://
schemas.google.com/g/2005#kind"/>

<batch:id>batchID_1</batch:id>
<batch:operation type="query"/>
<id>http://www.google.com/m8/feeds/contacts/cleari...@gmail.com/
base/4670a60d0c5d8b35</id>
<category term="http://schemas.google.com/contact/2008#contact"
scheme="http://schemas.google.com/g/2005#kind"/>
</entry></feed>

Trevor Johns

unread,
Sep 17, 2008, 1:58:17 AM9/17/08
to google-co...@googlegroups.com

Yes, it should work, and I don't see anything obviously wrong with
your XML. What URL are you sending this request to?

--
Trevor Johns

ct

unread,
Sep 17, 2008, 2:19:22 PM9/17/08
to Google Contacts API
The batch URL is:
http://www.google.com/m8/feeds/contacts/cleari...@gmail.com/full/batch

However searching through the forums, I think I should be posting a
contact's self link to the query instead of the contact's ID (which
looks like you just need to replace "/base/" with "/full/"). This
wasn't really clear in the documentation. Is there a way to query
using the contact's ID? I'm assuming the ID is guaranteed never to
change while the self link could.

On Sep 17, 1:58 am, "Trevor Johns" <tjo...@google.com> wrote:
> On Tue, Sep 16, 2008 at 8:28 PM, ct <clearingt...@gmail.com> wrote:
>
> > Is it possible to do a batch query to return multiple contacts? This
> > is the batch XML I'm generating to query for just one contact and it
> > returns with the error "Invalid entry Id/Uri".
>
> > <feed xmlns:app="http://purl.org/atom/app#" xmlns:gd="http://
> > schemas.google.com/g/2005" xmlns:batch="http://schemas.google.com/
> > gdata/batch" xmlns:gContact="http://schemas.google.com/contact/2008"
> > xmlns="http://www.w3.org/2005/Atom"><category term="http://
> > schemas.google.com/contact/2008#contact" scheme="http://
> > schemas.google.com/g/2005#kind"/>
>
> > <batch:id>batchID_1</batch:id>
> > <batch:operation type="query"/>
> > <id>http://www.google.com/m8/feeds/contacts/clearingt...@gmail.com/

ct

unread,
Sep 17, 2008, 3:12:44 PM9/17/08
to Google Contacts API
I'm using the gdata-objectivec-client library and I'd like to batch
delete a bunch of contacts, for which their IDs are already known. To
do so, I'm making two batch requests - one to fetch the contacts' edit
links and the other to delete them. I think my fetch is wrong because
I can't delete the fetched objects.

Here are the main bits from my objective c code:

// Create empty contact to fetch the contact
NSString* googleContactID = ...; // contact id
GDataEntryContact* entry = [GDataEntryContact
contactEntryWithTitle:@""];
[entry setIdentifier:[googleContactID
stringByReplacingOccurrencesOfString:@"/base/" withString:@"/full/"]];
[entry setBatchOperation: [GDataBatchOperation
batchOperationWithType:kGDataBatchOperationQuery]];

// Send batch feed to fetch
GDataFeedContact *batchFeed = [GDataFeedContact contactFeed];
[batchFeed setEntriesWithEntries:[NSArray arrayWithObject:entry]];

GDataServiceGoogleContact *service = ...; // code to get service
[service fetchContactBatchFeedWithBatchFeed:batchFeed
forBatchFeedURL:batchURL delegate:self
didFinishSelector:@selector(batchOperationTicket:finishedWithFeed:)
didFailSelector:@selector(batchOperationTicket:failedWithError:)];

// On return, looping through batch results, set batch operation to
delete
GDataEntryContact *entry = [batchResults objectAtIndex:idx];
[entry setBatchOperation: [GDataBatchOperation
batchOperationWithType:kGDataBatchOperationDelete]];

// Send batch request again with deleted entries ...

The generated fetch XML is:
<feed xmlns:app="http://purl.org/atom/app#" xmlns:gd="http://
schemas.google.com/g/2005" xmlns:batch="http://schemas.google.com/
gdata/batch" xmlns:gContact="http://schemas.google.com/contact/2008"
xmlns="http://www.w3.org/2005/Atom"><category term="http://
schemas.google.com/contact/2008#contact" scheme="http://
schemas.google.com/g/2005#kind"/><entry><batch:id>batchID_1</
batch:id><batch:operation type="query"/><id>http://www.google.com/m8/
feeds/contacts/cleari...@gmail.com/full/4c89b1588dc8181a</
While the generated delete XML is:
<feed xmlns:app="http://purl.org/atom/app#" xmlns:gd="http://
schemas.google.com/g/2005" xmlns:batch="http://schemas.google.com/
gdata/batch" xmlns:gContact="http://schemas.google.com/contact/2008"
xmlns="http://www.w3.org/2005/Atom"><category term="http://
schemas.google.com/contact/2008#contact" scheme="http://
schemas.google.com/g/2005#kind"/><atom:entry><batch:operation
type="delete"/><gd:email address="a...@a.com" rel="http://
schemas.google.com/g/2005#other" primary="true"/><gd:postalAddress
rel="http://schemas.google.com/g/2005#home">Test</
gd:postalAddress><gd:phoneNumber rel="http://schemas.google.com/g/
2005#mobile">12341234</gd:phoneNumber><batch:id>batchID_2</
batch:id><batch:status code="200" reason="Success"/><id>http://
www.google.com/m8/feeds/contacts/cleari...@gmail.com/base/4c89b1588dc8181a</id><title
type="text">asdfasdfasdf</title><updated>2008-09-17T18:37:02Z</
updated><atom:link rel="http://schemas.google.com/contacts/2008/
rel#edit-photo" href="http://www.google.com/m8/feeds/photos/media/
cleari...@gmail.com/4c89b1588dc8181a/1B2M2Y8AsgTpgAmY7PhCfg"
type="image/*"/><atom:link rel="self" href="http://www.google.com/m8/
feeds/contacts/cleari...@gmail.com/full/4c89b1588dc8181a"
type="application/atom+xml"/><atom:link rel="edit" href="http://
www.google.com/m8/feeds/contacts/cleari...@gmail.com/full/4c89b1588dc8181a/1221676622710000"
type="application/atom+xml"/><atom:category term="http://
schemas.google.com/contact/2008#contact" scheme="http://
schemas.google.com/g/2005#kind"/></atom:entry></feed>

The delete XML comes back with an interrupted error:
The prefix "atom" for element "atom:entry" is not bound.

Please help!

On Sep 17, 2:19 pm, ct <clearingt...@gmail.com> wrote:
> The batch URL is:
> http://www.google.com/m8/feeds/contacts/clearingt...@gmail.com/full/batch
Reply all
Reply to author
Forward
0 new messages