I'm trying to retrieve all contacts from Google Contacts via Google's CardDAV API.
According to the CardDAV Developer's Guide, this should be done via sending a addressbook-multiget REPORT
. Which, according to RFC 6352, should look like this:
REPORT https://www.googleapis.com/carddav/v1/principals/foo@gmail.com/lists/default HTTP/1.1
Authorization: Bearer ya29.foo-bar
Depth: 1
Content-Type: text/xml; charset=UTF-8
Host: www.googleapis.com
Content-Length: 204
<C:addressbook-multiget xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav">
<D:prop>
<D:getetag />
<C:address-data>
<C:prop name="EMAIL"/>
</C:address-data>
</D:prop>
</C:addressbook-multiget>
Unfortunately, I'm constantly getting (400) Bad Request
for all REPORT
requests.
I do include Authorization header with OAuth2 access token and Depth header set to 1 in the request and I'm sending it to https://www.googleapis.com/carddav/v1/principals/foo@gmail.com/lists/default
via HTTPS. And I do have the access to CardDAV API granted in Developer Console.
Have anyone got this working and/or has a clue of what I should be doing differently?
You are missing one step. The multiget report will retrieve contacts, based on a list of resource uris (hrefs). See https://www.rfc-editor.org/rfc/rfc6352#section-8.7.1
To get the list of hrefs in the first place, you can:
WebDAV Sync is the preferred method, especially if you have large collections of contacts.