0

Google CardDAV API Developer's Guide is very brief when it comes to contact manipulation. The only hint about how to insert a new contact is this:

Client applications issue a POST request with the new contact in VCard 3.0 format. The response will contain the ID of the new contact.

This is the request I issue, but the response I get is 400 Bad Request:

POST https://www.googleapis.com/carddav/v1/principals/foo.bar@gmail.com/lists/default/ HTTP/1.1
Authorization: Bearer ya29.foobar
Content-Type: text/vcard; charset="UTF-8"
Host: www.googleapis.com
Content-Length: 77
Expect: 100-continue
Connection: Keep-Alive

BEGIN:VCARD
VERSION:3.0
FN:Foo Bar
UID:abc-def-fez-1234546578
END:VCARD

Anybody has a clue what am I missing here?

jansokoly
  • 1,994
  • 2
  • 18
  • 25

3 Answers3

0

have you tried to use a url such as this one? https://www.googleapis.com/carddav/v1/principals/foo.bar@gmail.com/lists/default/CARD_NAME.vcf

vhr
  • 1,528
  • 1
  • 13
  • 21
0

Do a PUT, not a POST. Like this:

PUT /carddav/v1/principals/foo.bar@gmail.com/lists/default/DEADBEEF.vcf
If-None-Match: *
Authorization: ...
Host: www.googleapis.com
Content-Type: text/vcard; charset="UTF-8"
Expect: 100-continue

BEGIN:VCARD
VERSION:3.0
PRODID:-//YouYou//Windows//EN
FN:Foo Bar
N:Bar;Foo;;;
UID:DEADBEEF
END:VCARD
hnh
  • 13,957
  • 6
  • 30
  • 40
0

Also be sure to include in your OAuth2.0 Scope access to the CARDDAV API: https://www.googleapis.com/auth/carddav

This took me forever to figure out my I was getting a "Insufficient permissions" error.

Derek Wade
  • 697
  • 8
  • 11