Skip to content

Instantly share code, notes, and snippets.

@Racum
Last active December 19, 2015 21:59
Show Gist options
  • Save Racum/6024633 to your computer and use it in GitHub Desktop.
Save Racum/6024633 to your computer and use it in GitHub Desktop.
# Handshake: (resolve the addressbook_path in order to cache it)
# Step 1: get [principal_path] from [server_root]:
$ curl -X PROPFIND --user [user]:[password] -H "Depth: 1" -d "<?xml version=\"1.0\" encoding=\"UTF-8\"?><A:propfind xmlns:A=\"DAV:\"><A:prop><A:current-user-principal/></A:prop></A:propfind>" [server_root] | xpath "/d:multistatus/d:response[1]/d:propstat/d:prop/d:current-user-principal/d:href/text()"
# Step 2: get [addressbook_list_path] from [principal_path]:
$ curl -X PROPFIND --user [user]:[password] -H "Depth: 1" -d "<?xml version=\"1.0\" encoding=\"UTF-8\"?><A:propfind xmlns:A=\"DAV:\"><A:prop><B:addressbook-home-set xmlns:B=\"urn:ietf:params:xml:ns:carddav\"/></A:prop></A:propfind>" [server_root][principal_path] | xpath "/d:multistatus/d:response[1]/d:propstat/d:prop/card:addressbook-home-set/d:href/text()"
# Step 3: get [addressbook_path] from [addressbook_list_path]:
$ curl -X PROPFIND --user [user]:[password] -H "Depth: 1" -d "<?xml version=\"1.0\" encoding=\"UTF-8\"?><A:propfind xmlns:A=\"DAV:\"></A:propfind>" [server_root][addressbook_lisaddressbook_list_patht_url] | xpath "/d:multistatus/d:response[2]/d:href/text()"
# Access:
# List vCards:
$ curl -X PROPFIND --user [user]:[password] [server_root][addressbook_path] -H "Depth: 1" | xpath "/d:multistatus/d:response/d:href/text()"
# Upload vCard:
$ curl -X PUT --user [user]:[password] [server_root][addressbook_path]/[UID].vcf --data-binary @[UID].vcf
# Download vCard:
$ curl -X GET --user [user]:[password] [server_root][addressbook_path]/[UID].vcf > [UID].vcf
# Delete vCard:
$ curl -X DELETE --user [user]:[password] [server_root][addressbook_path]/[UID].vcf
@tfl
Copy link

tfl commented Aug 31, 2013

thanks for sharing this - recently I had trouble uploading a vcard with curl using -d @data-file option but failed until I found your gist. Now I know, use --data-binary ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment