With the Google Contacts API, you can GET contact information using JSON, but is there a way to update it using JSON? I haven't had any success in my attempts, and continue to get a "content not allowed in prolog" error when I try (seemingly indicating that they're expecting XML in the PUT request).
On the GET request, I GET from following URL: http://www.google.com/m8/feeds/contacts/[email protected]/full?alt=json
When I want to update a contact using XML I PUT to the following type of URL (it varies based on which contact is being updated): http://www.google.com/m8/feeds/contacts/[email protected]/base/0
I've tried adding alt=json onto the PUT request, but that was just a shot in the dark since I haven't found any actual documentation to confirm updating using JSON is even possible. I'm doing this interaction in JS from a firefox addon, so that's why my preference is to use JSON (I've been working with E4X up until this point and find it to be pretty janky).
Any help would be greatly appreciated!
I see no traces about "update google contact using JSON in PUT".
Google dev guide says:
To update an existing contact, first retrieve the entry you want to update, modify it, and then send a PUT request with the updated entry in the message body to the contact's edit URL. Use the application/atom+xml content type
(from http://code.google.com/apis/contacts/docs/3.0/developers_guide_protocol.html#Updating )
Although it doesn't document about PUT a contact in json format, I've tried successful like this:
Request header:
PUT https://www.google.com/m8/feeds/contacts/default/full/{contactId}?alt=json
Content-Type: application/json
Request body:
{
"entry":{
"gd$name": {
"gd$fullName": {
"$t": "My Name"
},
"gd$givenName": {
"$t": "My"
},
"gd$familyName": {
"$t": "Name"
}
}
}
}
The basic idea is using the format similar to the result of GET with alt=json
.
However, in the case of Batch operations for Contacts, I'll get the error message Unsupported Output Format
.
Hope this is helpful for guys who want using Google's Contacts API with JSON.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With