Updating Contacts giving 400 Bad Request Error

280 views
Skip to first unread message

Cherry

unread,
Mar 17, 2008, 7:26:12 AM3/17/08
to Google Contacts API
Hi,
I am using the google contacts api to update google contacts.
I am using a .net client.
But whenever I try to send an updated contact to the server i get a
bad request error.
This is my code.
public void fnUpdateGoogleContact(XmlDocument
xdUpdatedGoogleContactEntry,string strAuthorizationKey, string
strEditUrl)
{
try
{
HttpWebRequest hwrRequest =
(HttpWebRequest)WebRequest.Create(strEditUrl);
hwrRequest.ContentType = "application/atom+xml";
hwrRequest.Headers.Add("Authorization: GoogleLogin
auth=" + strAuthorizationKey);
hwrRequest.Headers.Add("X-HTTP-Method-Override: PUT");
hwrRequest.Method = "POST";

string args =
xdUpdatedGoogleContactEntry.InnerXml.Replace("<?xml version=\"1.0\"
encoding=\"utf-8\"?>", "");
args = args.Replace(" xmlns:gd=\"http://
schemas.google.com/g/2005\"", "");
args = args.Replace(" xmlns=\"http://www.w3.org/2005/
Atom\"", "");
byte[] dataToSend = Encoding.ASCII.GetBytes(args);
hwrRequest.ContentLength = dataToSend.Length;
Stream st = hwrRequest.GetRequestStream();
st.Write(dataToSend, 0, dataToSend.Length);
st.Close();
HttpWebResponse response =
(HttpWebResponse)hwrRequest.GetResponse();
StreamReader sr = new
StreamReader(response.GetResponseStream());
string responseBodyText = sr.ReadToEnd();
sr.Close();
}
catch (SystemException ex)
{


}


}
Could anybody tell me why am i getting the error
Regards,
cherian

Cherry

unread,
Mar 17, 2008, 8:04:42 AM3/17/08
to Google Contacts API

Adding to the above question I would like to add a little more
information.
The final value of the variable args is
<entry>
<id>http://www.google.com/m8/feeds/contacts/cheriansabby
%40gmail.com/base/56</id>
<updated>2008-03-17T06:22:02.746Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/contact/2008#contact" />
<title type="text">Test Application</title>
<link rel="self" type="application/atom+xml" href="http://
www.google.com/m8/feeds/contacts/cheriansabby%40gmail.com/base/56" />
<link rel="edit" type="application/atom+xml" href="http://
www.google.com/m8/feeds/contacts/cheriansabby%40gmail.com/base/56/1205734922746000"
/>
<gd:email rel="http://schemas.google.com/g/2005#other"
address="testapp...@testapplication.com" primary="true" />
</entry>
regards,
cherian

Cherry

unread,
Mar 17, 2008, 8:08:00 AM3/17/08
to Google Contacts API, cherrian saby

Adding to the above information. the final value of the variable args
is
<entry>
<id>http://www.google.com/m8/feeds/contacts/cheriansabby
%40gmail.com/base/56</id>
<updated>2008-03-17T06:22:02.746Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/contact/2008#contact" />
<title type="text">Test Application</title>
<link rel="self" type="application/atom+xml" href="http://
www.google.com/m8/feeds/contacts/cheriansabby%40gmail.com/base/56" />
<link rel="edit" type="application/atom+xml" href="http://
www.google.com/m8/feeds/contacts/cheriansabby%40gmail.com/base/56/1205734922746000"
/>
<gd:email rel="http://schemas.google.com/g/2005#other"
address="testapp...@testapplication.com" primary="true" />
</entry>

regards,
Cherian

Tomek

unread,
Mar 17, 2008, 9:50:53 AM3/17/08
to Google Contacts API
The question is if you PUT entry to the correct URI (editURI). In your
case it should be:

http://www.google.com/m8/feeds/contacts/cheriansabby%40gmail.com/base/56/1205734922746000

Can you verify what URI are you trying to update entry with?

Regards,
Tomek

On Mar 17, 1:08 pm, Cherry <cheriansa...@gmail.com> wrote:
> Adding to the above information. the final value of the variable args
> is
> <entry>
>          <id>http://www.google.com/m8/feeds/contacts/cheriansabby
> %40gmail.com/base/56</id>
>            <updated>2008-03-17T06:22:02.746Z</updated>
>           <category scheme="http://schemas.google.com/g/2005#kind"
> term="http://schemas.google.com/contact/2008#contact" />
>           <title type="text">Test Application</title>
>          <link rel="self" type="application/atom+xml" href="http://www.google.com/m8/feeds/contacts/cheriansabby%40gmail.com/base/56" />
>         <link rel="edit" type="application/atom+xml" href="http://www.google.com/m8/feeds/contacts/cheriansabby%40gmail.com/base/56/120..."
> />
>         <gd:email rel="http://schemas.google.com/g/2005#other"
> address="testapplicat...@testapplication.com" primary="true" />
> </entry>
>
> regards,
> Cherian

Cherry

unread,
Mar 17, 2008, 9:56:55 AM3/17/08
to Google Contacts API
thanks tomek,
The url I am using is the one you have specified.
i.e. href specified in the link tag inside the entry element.
<link rel='edit' type='application/atom+xml'
href='http://www.google.com/m8/feeds/contacts/liz%40gmail.com/
base/8411573/1204224422303000' />
But it still doesnt seem to work.
regards,
Cherian

Tomek

unread,
Mar 17, 2008, 10:31:33 AM3/17/08
to Google Contacts API
The URI I have given you comes from the XML you have provided - the
URI has to be the same as in Edit link in the retrieved contact entry.
Do you still receive 400 Bad Request error?

Regards,
Tomek

Cherry

unread,
Mar 18, 2008, 5:29:05 AM3/18/08
to Google Contacts API
hi tomek,
The uri which I give is the same as the Uri specified in the XML i.e
inside the entry element.
I still receive the 400 bad request error.
One more question.
For example if this was my original entry element

<entry>
<id>http://www.google.com/m8/feeds/contacts/cheriansabs
%40gmail.com/base/243</id>
<updated>2008-03-12T06:02:37.656Z</updated>
<title type='text'>xyz</title>
<content type='text'>dfsfsfsdfs</content>
<link rel='self' type='application/atom+xml' href='http://
www.google.com/m8/feeds/contacts/csabs%40gmail.com/base/243'/>
<link rel='edit' type='application/atom+xml' href='http://
www.google.com/m8/feeds/contacts/csabs%40gmail.com/base/243/1205301757656000'/>
address='x...@abc.com' primary='true'/>
<gd:email rel='http://schemas.google.com/g/2005#work'
address='a...@def.com'/>
<gd:phoneNumber rel='http://schemas.google.com/g/
2005#work_fax'>230940923409</gd:phoneNumber>
<gd:phoneNumber rel='http://schemas.google.com/g/
2005#work'>2308949023</gd:phoneNumber>
</entry>



Now i just want to want to update primary email address.
So while updating a contact, do i have to send the entire original
entry element with the modified primary address i.e.

<entry>
<id>http://www.google.com/m8/feeds/contacts/cheriansabs
%40gmail.com/base/243</id>
<updated>2008-03-12T06:02:37.656Z</updated>
<title type='text'>xyz</title>
<content type='text'>dfsfsfsdfs</content>
<link rel='self' type='application/atom+xml' href='http://
www.google.com/m8/feeds/contacts/csabs%40gmail.com/base/243'/>
<link rel='edit' type='application/atom+xml' href='http://
www.google.com/m8/feeds/contacts/csabs%40gmail.com/base/243/1205301757656000'/>
address='b...@cbc.com' primary='true'/>
<gd:email rel='http://schemas.google.com/g/2005#work'
address='a...@def.com'/>
<gd:phoneNumber rel='http://schemas.google.com/g/
2005#work_fax'>230940923409</gd:phoneNumber>
<gd:phoneNumber rel='http://schemas.google.com/g/
2005#work'>2308949023</gd:phoneNumber>
</entry>


or should the modified field be included only i.e.
<entry>
<id>http://www.google.com/m8/feeds/contacts/cheriansabs
%40gmail.com/base/243</id>
<updated>2008-03-12T06:02:37.656Z</updated>
<title type='text'>xyz</title>
<content type='text'>dfsfsfsdfs</content>
<link rel='self' type='application/atom+xml' href='http://
www.google.com/m8/feeds/contacts/csabs%40gmail.com/base/243'/>
<link rel='edit' type='application/atom+xml' href='http://
www.google.com/m8/feeds/contacts/csabs%40gmail.com/base/243/1205301757656000'/>
address='b...@cbc.com' primary='true'/>
</entry>

Sebastian Adamczyk

unread,
Mar 18, 2008, 10:08:23 AM3/18/08
to Google Contacts API
Hi,

You should provide all the fields because in other cases you will
remove all the other ones.
I believe that if you provide the wrong version id the error should be
409 version conflict error.

I can see in the code that you have provided:
hwrRequest.Headers.Add("X-HTTP-Method-Override: PUT");
hwrRequest.Method = "POST";

Shouldn't the method also be "PUT"?

Best regards,
Sebastian

On Mar 18, 10:29 am, Cherry <cheriansa...@gmail.com> wrote:
> hi tomek,
> The uri which I give is the same as the Uri specified in the XML i.e
> inside the entry element.
> I still receive the 400 bad request error.
> One more question.
> For example if this was my original entry element
>
> <entry>
> <id>http://www.google.com/m8/feeds/contacts/cheriansabs
> %40gmail.com/base/243</id>
> <updated>2008-03-12T06:02:37.656Z</updated>
> <category scheme='http://schemas.google.com/g/2005#kind'
> term='http://schemas.google.com/contact/2008#contact'/>
> <title type='text'>xyz</title>
> <content type='text'>dfsfsfsdfs</content>
> <link rel='self' type='application/atom+xml' href='http://www.google.com/m8/feeds/contacts/csabs%40gmail.com/base/243'/>
> <link rel='edit' type='application/atom+xml' href='http://www.google.com/m8/feeds/contacts/csabs%40gmail.com/base/243/120530175...>
> address='...@abc.com' primary='true'/>
> address='...@def.com'/>
> <gd:phoneNumber rel='http://schemas.google.com/g/
> 2005#work_fax'>230940923409</gd:phoneNumber>
> <gd:phoneNumber rel='http://schemas.google.com/g/
> 2005#work'>2308949023</gd:phoneNumber>
> </entry>
>
> Now i just want to want to update primary email address.
> So while updating a contact, do i have to send the entire original
> entry element with the modified primary address i.e.
>
> <entry>
> <id>http://www.google.com/m8/feeds/contacts/cheriansabs
> %40gmail.com/base/243</id>
> <updated>2008-03-12T06:02:37.656Z</updated>
> <category scheme='http://schemas.google.com/g/2005#kind'
> term='http://schemas.google.com/contact/2008#contact'/>
> <title type='text'>xyz</title>
> <content type='text'>dfsfsfsdfs</content>
> <link rel='self' type='application/atom+xml' href='http://www.google.com/m8/feeds/contacts/csabs%40gmail.com/base/243'/>
> <link rel='edit' type='application/atom+xml' href='http://www.google.com/m8/feeds/contacts/csabs%40gmail.com/base/243/120530175...>
> address='...@cbc.com' primary='true'/>
> address='...@def.com'/>
> <gd:phoneNumber rel='http://schemas.google.com/g/
> 2005#work_fax'>230940923409</gd:phoneNumber>
> <gd:phoneNumber rel='http://schemas.google.com/g/
> 2005#work'>2308949023</gd:phoneNumber>
> </entry>
>
> or should the modified field be included only i.e.
> <entry>
> <id>http://www.google.com/m8/feeds/contacts/cheriansabs
> %40gmail.com/base/243</id>
> <updated>2008-03-12T06:02:37.656Z</updated>
> <category scheme='http://schemas.google.com/g/2005#kind'
> term='http://schemas.google.com/contact/2008#contact'/>
> <title type='text'>xyz</title>
> <content type='text'>dfsfsfsdfs</content>
> <link rel='self' type='application/atom+xml' href='http://www.google.com/m8/feeds/contacts/csabs%40gmail.com/base/243'/>
> <link rel='edit' type='application/atom+xml' href='http://www.google.com/m8/feeds/contacts/csabs%40gmail.com/base/243/120530175...>
> address='...@cbc.com' primary='true'/>
> </entry>

Cherry

unread,
Mar 18, 2008, 10:33:22 AM3/18/08
to Google Contacts API
thanks sebastian.

I haven't understood what you meant by this statement.
"You should provide all the fields because in other cases you will
remove all the other ones. "

Well about the method being "put" I have tried all combinations but to
no avail

//hwrRequest.Headers.Add("X-HTTP-Method-Override:
PUT");
hwrRequest.Method = "PUT";
//hwrRequest.Method = "POST";


hwrRequest.Headers.Add("X-HTTP-Method-Override: PUT");
//hwrRequest.Method = "PUT";
hwrRequest.Method = "POST";

hwrRequest.Headers.Add("X-HTTP-Method-Override: PUT");
hwrRequest.Method = "PUT";
hwrRequest.Method = "POST";

I dont know what exactly is my problem

regards,
Cherian

Tomek

unread,
Mar 18, 2008, 10:41:36 AM3/18/08
to Google Contacts API
Hi Cherian,

Sebastian meant that if you update (PUT) a new contact entry it will
totally overwrite the previous one - removing field means removing
entries' data - you have to provide full updated contact data (even if
only email has changed).

Getting back to your problem with 400 error. Can you try using 'curl'?
It will provide you with all the details of communication is happening
between you and Contacts API (like headers, etc.).

You can find some hints how to use it @
http://code.google.com/apis/contacts/developers_guide_protocol.html

Regards,
Tomek

the easiest way to trace your problem

Sebastian Adamczyk

unread,
Mar 18, 2008, 10:54:25 AM3/18/08
to Google Contacts API
Hi,

Tomek is right, the best way would be to use curl.
Just one more comment about the method (regardless of the problem).
You should use PUT not POST. PUT is used for updating an existing
contact, POST is adding a new contact.

Best regards,
Sebastian

On Mar 18, 3:41 pm, Tomek <tdziekon...@google.com> wrote:
> Hi Cherian,
>
> Sebastian meant that if you update (PUT) a new contact entry it will
> totally overwrite the previous one - removing field means removing
> entries' data - you have to provide full updated contact data (even if
> only email has changed).
>
> Getting back to your problem with 400 error. Can you try using 'curl'?
> It will provide you with all the details of communication is happening
> between you and Contacts API (like headers, etc.).
>
> You can find some hints how to use it @http://code.google.com/apis/contacts/developers_guide_protocol.html

Tomek

unread,
Mar 18, 2008, 11:10:20 AM3/18/08
to Google Contacts API
But still you can use POST with HTTP header:

X-HTTP-Method-Override: PUT

which in curl you can achieve by adding -H parameter.
(the same for DELETE)

Regards,
Tomek

Sebastian Kanthak

unread,
Mar 18, 2008, 2:26:11 PM3/18/08
to google-co...@googlegroups.com
Cherian,

I believe you have to set the request's Content-Length header
manually. POST or PUT requests without a Content-Length header will be
rejected by our servers.

Sebastian

Cherry

unread,
Mar 19, 2008, 12:22:22 AM3/19/08
to Google Contacts API
Thanks tomek ,

I am not very sure if we could use curl in c#.net

warm regards,
Cherian

Cherry

unread,
Mar 19, 2008, 12:26:26 AM3/19/08
to Google Contacts API

Thanks sebastian,
But I am setting the content length as illustrated by my code.
But It is still not working.
regards,
Cherian

Cherry

unread,
Mar 19, 2008, 12:55:22 AM3/19/08
to Google Contacts API
hi sebastian and tomek
Now i am getting the same 400 bad request error while creating a new
contact. This is my code.
public void fnCreateNewGoogleContact(String strNewGoogleContactEntry,
string strAuthorizationKey, string strEditUrl)
{
try
{
WebRequest hwrRequest = WebRequest.Create(strEditUrl);
hwrRequest.ContentType = "application/atom+xml";
hwrRequest.Headers.Add("Authorization: GoogleLogin
auth=" + strAuthorizationKey);
hwrRequest.Method = "POST";
byte[] dataToSend =
Encoding.ASCII.GetBytes(strNewGoogleContactEntry);
hwrRequest.ContentLength = dataToSend.Length;
Stream st = hwrRequest.GetRequestStream();
st.Write(dataToSend, 0, dataToSend.Length);
st.Close();
HttpWebResponse response =
(HttpWebResponse)hwrRequest.GetResponse();
StreamReader sr = new
StreamReader(response.GetResponseStream());
string responseBodyText = sr.ReadToEnd();
sr.Close();
}
catch (SystemException ex)
{


}

}

the value of my new entry contact is
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://
schemas.google.com/g/2005">
<atom:category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/contact/2008#contact" />
<atom:title type="text">Auto</atom:title>
</atom:entry>

the value of the url is
http://www.google.com/m8/feeds/contacts/cherian%40gmail.com/base

Now i guess both the problems for creating a new google contact and
updating a contact might be similar in nature.

Regards,
Cherry

Sebastian Kanthak

unread,
Mar 19, 2008, 2:34:21 AM3/19/08
to google-co...@googlegroups.com

sorry for not noticing that you set the Content-Length header properly.

I just posted the xml you gave with curl (removing the new-line in the
xmlns:gd attribute) and successfully created the contact. Did you
inspect the body of the response? It usually contains an error
message.

Could you send us a log of the literal http traffic that is exchanged?
You could obtain that using a network protocol analyzer like
"Wireshark".

Thanks,
Sebastian

Cherry

unread,
Mar 19, 2008, 3:42:49 AM3/19/08
to Google Contacts API
thanks sebastian,
The creation of new contacts is working.
But its the updation of contacts that is still giving me a problem.
I have downloaded wireshark.
I will try to figure out how to work with wireshark.
Will let u know the details
As for the error message in the body of the response, it stated a bad
request error.

regards,
Cherian

Cherry

unread,
Mar 19, 2008, 4:30:57 AM3/19/08
to Google Contacts API

Cherry

unread,
Mar 19, 2008, 9:45:40 AM3/19/08
to Google Contacts API

hi,
sebastian
these are the logs i could capture with wireshark related to

23 8.345870 192.168.0.18 64.233.183.99 HTTP PUT /m8/feeds/contacts/
cheriansabby%40gmail.com/base/56/1205734922746000 HTTP/1.1
(application/atom+xml)



29 8.806234 64.233.183.99 192.168.0.18 HTTP HTTP/1.1 400 Bad Request
(text/plain)


I hope this could help solving my problem.

regards,
Cherian

Sebastian Kanthak

unread,
Mar 19, 2008, 9:45:17 PM3/19/08
to google-co...@googlegroups.com

this is only the summary / request headers. I'd need the actual
payload (i.e., everything that is sent via http).

>
>
>
> regards,
> Cherian
> >
>

Cherry

unread,
Mar 20, 2008, 12:42:11 AM3/20/08
to Google Contacts API

hi sebastian,
I hope this is what you are looking out for..

0000 50 55 54 20 2f 6d 38 2f 66 65 65 64 73 2f 63 6f PUT /m8/
feeds/co
0010 6e 74 61 63 74 73 2f 63 68 65 72 69 61 6e 73 61 ntacts/c
heriansa
0020 62 62 79 25 34 30 67 6d 61 69 6c 2e 63 6f 6d 2f bby%40gm
ail.com/
0030 62 61 73 65 2f 35 36 2f 31 32 30 35 37 33 34 39 base/56/
12057349
0040 32 32 37 34 36 30 30 30 20 48 54 54 50 2f 31 2e 22746000
HTTP/1.
0050 31 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 1..Conte nt-
Type:
0060 20 61 70 70 6c 69 63 61 74 69 6f 6e 2f 61 74 6f applica tion/
ato
0070 6d 2b 78 6d 6c 0d 0a 41 75 74 68 6f 72 69 7a 61 m+xml..A
uthoriza
0080 74 69 6f 6e 3a 20 47 6f 6f 67 6c 65 4c 6f 67 69 tion: Go
ogleLogi
0090 6e 20 61 75 74 68 3d 44 51 41 41 41 48 4d 41 41 n auth=D
QAAAHMAA
00a0 41 44 64 6e 64 73 4c 62 4d 6b 55 75 71 43 32 4e ADdndsLb
MkUuqC2N
00b0 6e 68 32 43 4c 48 65 45 4b 62 34 66 45 65 5a 70 nh2CLHeE
Kb4fEeZp
00c0 4d 72 6f 53 4c 35 54 64 64 59 42 42 67 51 50 51 MroSL5Td
dYBBgQPQ
00d0 39 4b 50 43 6e 6a 71 30 47 72 78 52 54 31 38 54 9KPCnjq0
GrxRT18T
00e0 50 6d 52 37 4c 39 62 37 69 48 4d 6c 65 70 57 73 PmR7L9b7
iHMlepWs
00f0 59 43 73 33 47 6d 56 55 74 62 49 50 55 73 72 6e YCs3GmVU
tbIPUsrn
0100 38 79 47 6f 5f 57 57 6c 56 5a 30 6c 34 6f 47 62 8yGo_WWl
VZ0l4oGb
0110 44 46 57 6e 7a 51 66 53 75 56 41 69 45 42 79 49 DFWnzQfS
uVAiEByI
0120 6c 6a 32 66 73 38 47 4d 66 6e 78 34 35 6a 6e 2d lj2fs8GM
fnx45jn-
0130 5f 2d 4d 6d 36 47 68 75 43 38 72 64 5a 52 49 48 _-Mm6Ghu
C8rdZRIH
0140 65 37 39 39 65 35 39 48 51 62 4e 6b 67 0d 0a 48 e799e59H
QbNkg..H
0150 6f 73 74 3a 20 77 77 77 2e 67 6f 6f 67 6c 65 2e ost:
www .google.
0160 63 6f 6d 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e com..Con tent-
Len
0170 67 74 68 3a 20 35 39 39 0d 0a 45 78 70 65 63 74 gth:
599 ..Expect
0180 3a 20 31 30 30 2d 63 6f 6e 74 69 6e 75 65 0d 0a : 100-co
ntinue..
0190 0d 0a 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d ..<?xml
version=
01a0 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 "1.0" en
coding="
01b0 75 74 66 2d 38 22 3f 3e 3c 65 6e 74 72 79 20 78 utf-8"?>
<entry x
01c0 6d 6c 6e 73 3a 67 64 3d 22 68 74 74 70 3a 2f 2f mlns:gd=
"http://
01d0 73 63 68 65 6d 61 73 2e 67 6f 6f 67 6c 65 2e 63 schemas.
google.c
01e0 6f 6d 2f 67 2f 32 30 30 35 22 3e 3c 69 64 3e 68 om/g/200
5"><id>h
01f0 74 74 70 3a 2f 2f 77 77 77 2e 67 6f 6f 67 6c 65 ttp://ww
w.google
0200 2e 63 6f 6d 2f 6d 38 2f 66 65 65 64 73 2f 63 6f .com/m8/
feeds/co
0210 6e 74 61 63 74 73 2f 63 68 65 72 69 61 6e 73 61 ntacts/c
heriansa
0220 62 62 79 25 34 30 67 6d 61 69 6c 2e 63 6f 6d 2f bby%40gm
ail.com/
0230 62 61 73 65 2f 35 36 3c 2f 69 64 3e 3c 63 61 74 base/56< /
id><cat
0240 65 67 6f 72 79 20 73 63 68 65 6d 65 3d 22 68 74 egory sc
heme="ht
0250 74 70 3a 2f 2f 73 63 68 65 6d 61 73 2e 67 6f 6f tp://sch
emas.goo
0260 67 6c 65 2e 63 6f 6d 2f 67 2f 32 30 30 35 23 6b gle.com/ g/
2005#k
0270 69 6e 64 22 20 74 65 72 6d 3d 22 68 74 74 70 3a ind" ter
m="http:
0280 2f 2f 73 63 68 65 6d 61 73 2e 67 6f 6f 67 6c 65 //schema
s.google
0290 2e 63 6f 6d 2f 63 6f 6e 74 61 63 74 2f 32 30 30 .com/con tact/
200
02a0 38 23 63 6f 6e 74 61 63 74 22 20 2f 3e 3c 74 69 8#contac t" /
><ti
02b0 74 6c 65 20 74 79 70 65 3d 22 74 65 78 74 22 3e tle type
="text">
02c0 47 61 61 6e 64 4d 61 61 72 6f 3c 2f 74 69 74 6c GaandMaa ro</
titl
02d0 65 3e 3c 6c 69 6e 6b 20 72 65 6c 3d 22 73 65 6c e><link
rel="sel
02e0 66 22 20 74 79 70 65 3d 22 61 70 70 6c 69 63 61 f" type=
"applica
02f0 74 69 6f 6e 2f 61 74 6f 6d 2b 78 6d 6c 22 20 68 tion/ato m
+xml" h
0300 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e ref="htt p://www.
0310 67 6f 6f 67 6c 65 2e 63 6f 6d 2f 6d 38 2f 66 65 google.c om/
m8/fe
0320 65 64 73 2f 63 6f 6e 74 61 63 74 73 2f 63 68 65 eds/cont acts/
che
0330 72 69 61 6e 73 61 62 62 79 25 34 30 67 6d 61 69 riansabb y
%40gmai
0340 6c 2e 63 6f 6d 2f 62 61 73 65 2f 35 36 22 20 2f l.com/ba se/
56" /
0350 3e 3c 6c 69 6e 6b 20 72 65 6c 3d 22 65 64 69 74 ><link r
el="edit
0360 22 20 74 79 70 65 3d 22 61 70 70 6c 69 63 61 74 " type="
applicat
0370 69 6f 6e 2f 61 74 6f 6d 2b 78 6d 6c 22 20 68 72 ion/atom
+xml" hr
0380 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67 ef="http ://
www.g
0390 6f 6f 67 6c 65 2e 63 6f 6d 2f 6d 38 2f 66 65 65 oogle.co m/m8/
fee
03a0 64 73 2f 63 6f 6e 74 61 63 74 73 2f 63 68 65 72 ds/conta cts/
cher
03b0 69 61 6e 73 61 62 62 79 25 34 30 67 6d 61 69 6c iansabby
%40gmail
03c0 2e 63 6f 6d 2f 62 61 73 65 2f 35 36 2f 31 32 30 .com/bas e/
56/120
03d0 35 37 33 34 39 32 32 37 34 36 30 30 30 22 20 2f 57349227
46000" /
03e0 3e 3c 2f 65 6e 74 72 79 3e ></entry
>

Regards,
Cherian Sabby

Cherry

unread,
Mar 20, 2008, 1:31:46 AM3/20/08
to Google Contacts API
hi sebastian,
I just noticed something strange
I am getting some junk values before my entry element.
0000 00 17 9a 30 0d 18 00 1d 60 25 33 d8 08 00 45 00 ...0.... `
%3...E.
0010 02 7f 26 a8 40 00 80 06 a6 5d c0 a8 00 0d d1
55 ..&.@... .].....U
0020 99 68 05 60 00 50 1b f9 28 44 1d dd 5c 80 50 18 .h.`.P.. (D..
\.P.
0030 ff ff ab 78 00 00 3c 3f 78 6d 6c 20 76 65 72 73 ...x..<? xml
vers
0040 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 ion="1.0 "
encodi
0050 6e 67 3d 22 75 74 66 2d 38 22 3f 3e 3c 65 6e 74 ng="utf- 8"?
><ent
0060 72 79 20 78 6d 6c 6e 73 3a 67 64 3d 22 68 74 74 ry
xmlns :gd="htt
0070 70 3a 2f 2f 73 63 68 65 6d 61 73 2e 67 6f 6f 67 p://sche
mas.goog
0080 6c 65 2e 63 6f 6d 2f 67 2f 32 30 30 35 22 3e 3c le.com/g /
2005"><

I dont understand how this happened .While previously with the same
code i got the output as shown in the above post.
Any clues why this happened.
regards,
Cherian

Cherry

unread,
Mar 20, 2008, 1:50:35 AM3/20/08
to Google Contacts API

hi sebastian
I have a feeling that my headers are not getting attached to the
rquest.
Any clues why this is happening.
regards,
Cherian Sabby

Cherry

unread,
Mar 20, 2008, 2:12:21 AM3/20/08
to Google Contacts API
im sorry
my bad
Headers are getting attached.
This is the payload which is getting attached with the HTTP Request.
I got this using Sharkwire



POST /m8 /feeds/c
ontacts/ cherians
abby%40g mail.com
/base/56 /1205734
92274600 0 HTTP/1
.1..Cont ent-Type
: applic ation/at
om+xml.. Authoriz
ation: G oogleLog
in auth= DQAAAHIA
AACm2RDS Tcr_oipe
cjKmgdhD 4ZFcwg0I
Exk37fZG ENhyDD1d
fx9Rvb43 3HIN683G
39aTy-Bc U14r-d_p
9AFzwKJw MLjNOg98
yTX5q5bE yHX9eInc
WPEe8QEn kXo30fmo
fxmxKsr- 4ncywAsD
LcgmXl0y psesYfYc
RkVO2cKK 9VLQOA..
X-HTTP-M ethod-Ov
erride: PUT..Hos
t: www.g oogle.co
m..Conte nt-Lengt
h: 555.. Expect:
100-cont inue....
<?xml ve rsion="1
.0" enco ding="ut
f-8"?><e ntry><id
>http:// www.goog
le.com/m 8/feeds/
contacts /cherian
sabby%40 gmail.co
m/base/5 6</id><c
ategory scheme="
http://s chemas.g
oogle.co m/g/2005
#kind" t erm="htt
p://sche mas.goog
le.com/c ontact/2
008#cont act" /><
title ty pe="text
">ABc</ti
tle><lin k rel="s
elf" typ e="appli
cation/a tom+xml"
href="h ttp://ww
w.google .com/m8/
feeds/co ntacts/c
heriansa bby%40gm
ail.com/ base/56"
/><link rel="ed
it" type ="applic
ation/at om+xml"
href="ht tp://www
.google. com/m8/f
eeds/con tacts/ch
eriansab by%40gma
il.com/b ase/56/1
20573492 2746000"
/></ent ry>

I hope this might give you a better idea of my problem.
Regards,
Cherian

Cherry

unread,
Mar 21, 2008, 6:38:06 AM3/21/08
to Google Contacts API

hi sebastian,
Did you get any clue why my code might not be working.
Maybe you might be busy with the holy week going on.
Hope you do find out time to solve my problem.
Happy easter in advance .
regards,
Cherry

Jarek

unread,
Mar 21, 2008, 6:54:05 AM3/21/08
to google-co...@googlegroups.com
Cherry,

Maybe you can simplify our life a bit :) with parsing the payload? Can you do this again and choose "Follow TCP stream" option in Wireshark and copy us the result? This would be much easier to parse and find problems...

Regards,

Jarek
--
Jarek Potiuk
Phone: +48 664 09 55 09

Cherry

unread,
Mar 24, 2008, 6:17:26 AM3/24/08
to Google Contacts API

hey hi jarek,
how are you.
As per your wish, I have followed your steps and have got the TCP
stream.
The following is the output.

POST /m8/feeds/contacts/cheriansabby%40gmail.com/base/
bc2bb83/1206094664312000 HTTP/1.1

Content-Type: application/atom+xml

Authorization: GoogleLogin
auth=DQAAAHEAAACq_bRpIxM99AS0pNjH4ykrg2M1nNd9-A9PBxgtB-
CWSfedJUnPKpN1nyreggzoJ8HtFWUBo0LVqPPHtX0ejnbltBjlDIrhLCMGxFnpxsbvJLsh1-
B2NRZOLWN_0_qWadLkhVM-wEjaK2iExrTZq-70J7Ssn0bEAJ8jAbJb2B5cYg

X-HTTP-Method-Override: PUT

Host: www.google.com

Content-Length: 560



<?xml version="1.0" encoding="utf-8"?><entry><id>http://www.google.com/
m8/feeds/contacts/cheriansabby%40gmail.com/base/bc2bb83</id><category
schemas.google.com/contact/2008#contact" /><title type="text"></
title><link rel="self" type="application/atom+xml" href="http://
www.google.com/m8/feeds/contacts/cheriansabby%40gmail.com/base/bc2bb83"
/><link rel="edit" type="application/atom+xml" href="http://
www.google.com/m8/feeds/contacts/cheriansabby%40gmail.com/base/bc2bb83/1206094664312000"
/></entry>

Hope this is what your looking out for.
Thanks for the suggestion.

Regards,
Cherry

Sebastian Kanthak

unread,
Mar 24, 2008, 2:28:31 PM3/24/08
to google-co...@googlegroups.com
Cherry,

I just tried an identical request. The contact your are trying to
update is empty (it does not contain a name, nor an email). The server
does not accept empty contacts.

The body of the http response is the following string (in addition to
the status being "400 Bad Request"): "Entry does not have any fields
set."

Try setting a name (title) on the contact.

Sebastian

Cherry

unread,
Mar 25, 2008, 2:03:03 AM3/25/08
to Google Contacts API

thanks Sebastian,
I have a contact in gmail with only the primary email set and all
other fields set to blank.
i.e. a...@abc.com
Ok now i tried updating the contact in two ways.

The first time "Entry does not have any fields
set." error popped up.

This was the tcp stream.

POST /m8/feeds/contacts/cheriansabby%40gmail.com/base/
bc2bb83/1206363832448000 HTTP/1.1

Content-Type: application/atom+xml

Authorization: GoogleLogin
auth=DQAAAHIAAACWy86UVXEMntD5ByrW8AqqhqQiJ2g7jsKW8XWJ-
ATLIY_WPePzuNoNCbTxNz0G59kAt3PKsuTuCupYqyBs6g45-
p1JHD9zhtT7nTtipVCEoMzUPPQoPpAMOkV2X0Phnje40OiArB3B-
aUSD4L0g_uPVuP_M8jwCAHYtlfBtSt7cA

X-HTTP-Method-Override: PUT

Host: www.google.com

Content-Length: 1533

Connection: Close



<entry><id xmlns="http://www.w3.org/2005/Atom">http://www.google.com/
m8/feeds/contacts/cheriansabby%40gmail.com/base/bc2bb83</id><updated
xmlns="http://www.w3.org/2005/Atom">2008-03-24T13:03:52.448Z</
updated><category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/contact/2008#contact" xmlns="http://
www.w3.org/2005/Atom" /><title type="text">Yogesh PR</title><link
rel="self" type="application/atom+xml" href="http://www.google.com/m8/
feeds/contacts/cheriansabby%40gmail.com/base/bc2bb83" xmlns="http://
www.w3.org/2005/Atom" /><link rel="edit" type="application/atom+xml"
href="http://www.google.com/m8/feeds/contacts/cheriansabby%40gmail.com/
base/bc2bb83/1206363832448000" xmlns="http://www.w3.org/2005/Atom" /
><gd:organisation xmlns:gd="http://schemas.google.com/g/
2005"><gd:orgTitle>Yogesh PR</gd:orgTitle></gd:organisation><gd:email
rel="http://schemas.google.com/g/2005#other" address="a...@abc.com"
primary="true" xmlns:gd="http://schemas.google.com/g/2005" /
><gd:phoneNumber rel="http://schemas.google.com/g/2005#work_fax#"
xmlns:gd="http://schemas.google.com/g/2005">34534</
gd:phoneNumber><gd:phoneNumber rel="http://schemas.google.com/g/
2005#work#" xmlns:gd="http://schemas.google.com/g/2005">34534</
gd:phoneNumber><gd:phoneNumber rel="http://schemas.google.com/g/
2005#home#" xmlns:gd="http://schemas.google.com/g/2005">345345</
gd:phoneNumber><gd:phoneNumber rel="http://schemas.google.com/g/
2005#mobile#" xmlns:gd="http://schemas.google.com/g/2005">345345</
gd:phoneNumber></entry>HTTP/1.1 400 Bad Request

Content-Type: text/plain; charset=UTF-8

Transfer-Encoding: chunked

Expires: Tue, 25 Mar 2008 05:36:10 GMT

Cache-Control: private, max-age=0

Date: Tue, 25 Mar 2008 05:36:11 GMT

Server: GFE/1.3

Connection: Close



23

Entry does not have any fields set.

0





The second time I tried updating the contacts without adding the name
spaces and i got the following error.
"org.xml.sax.SAXParseException: The prefix &quot;gd&quot; for element
&quot;gd:organisation&quot; is not bound."
This was the tcp stream
POST /m8/feeds/contacts/cheriansabby%40gmail.com/base/
bc2bb83/1206363832448000 HTTP/1.1

Content-Type: application/atom+xml

Authorization: GoogleLogin auth=DQAAAHIAAABlKZ3LDQ9u1yXP7LhHdFENM-
VQeeCnPSaixlo_dJGrb87tUIBW_XRvOGDhEV16yULL-
yFu7sWTTPdNteFA1MlumiHdHVHKySoFI3IuDdNTxd0GJ7_z965c5xjzozuhkANpwmqei_Jt6h7K-
yeTTz-VjnTn1pJmmjuDowa8HiIlpw

X-HTTP-Method-Override: PUT

Host: www.google.com

Content-Length: 1089

Connection: Close



<entry><id>http://www.google.com/m8/feeds/contacts/cheriansabby
%40gmail.com/base/bc2bb83</id><updated>2008-03-24T13:03:52.448Z</
updated><category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/contact/2008#contact" /><title
type="text">Yogesh PR</title><link rel="self" type="application/atom
%40gmail.com/base/bc2bb83/1206363832448000" /
><gd:organisation><gd:orgTitle>Yogesh PR</gd:orgTitle></
gd:organisation><gd:email rel="http://schemas.google.com/g/2005#other"
address="a...@abc.com" primary="true" /><gd:phoneNumber rel="http://
schemas.google.com/g/2005#work_fax#">34534</
gd:phoneNumber><gd:phoneNumber rel="http://schemas.google.com/g/
2005#work#">34534</gd:phoneNumber><gd:phoneNumber rel="http://
schemas.google.com/g/2005#home#">345345</
gd:phoneNumber><gd:phoneNumber rel="http://schemas.google.com/g/
2005#mobile#">345345</gd:phoneNumber></entry>HTTP/1.1 400 Bad Request

Content-Type: text/plain; charset=UTF-8

Transfer-Encoding: chunked

Expires: Tue, 25 Mar 2008 05:49:53 GMT

Cache-Control: private, max-age=0

Date: Tue, 25 Mar 2008 05:49:53 GMT

Server: GFE/1.3

Connection: Close



6e

org.xml.sax.SAXParseException: The prefix &quot;gd&quot; for element
&quot;gd:organisation&quot; is not bound.

0



I hope this might give you a clear idea of where I'm going wrong.

Thanks in advance.

Regards,
Cherry

Sebastian Kanthak

unread,
Mar 25, 2008, 2:12:53 AM3/25/08
to google-co...@googlegroups.com
Try adding this attribute to your top-level "entry" element. It
declares the "gd" namespace you're using.

<entry xmlns:gd='http://schemas.google.com/g/2005'>

Sebastian

Cherry

unread,
Mar 25, 2008, 2:26:54 AM3/25/08
to Google Contacts API
hi sebastian,
It still gives me the same error. I tried the above code.
"Entry does not have any fields set."
regards,
Cherian

Cherry

unread,
Mar 26, 2008, 1:17:36 AM3/26/08
to Google Contacts API
hi,
guys

Any clue why updating the contacts is not working in my case.
I still clueless, even after 32 posts I have not got a solution.
If you guys want me to try out something else, do let me know.


regards,
Cherry

Sebastian Kanthak

unread,
Mar 26, 2008, 7:39:51 PM3/26/08
to google-co...@googlegroups.com
Ah, you're missing another namespace declaration. This should be the
right entry tag:

<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:gd="http://schemas.google.com/g/2005">

Sebastian

Cherry

unread,
Mar 28, 2008, 12:23:24 AM3/28/08
to Google Contacts API

Many thanks,
So finally we have the updates working.
Thanks to all the contributors of this thread.
Special thanks to jarek and sebastian.
I hope the contacts api documentation could be little more clearer.
Regards,
Cherry

Reply all
Reply to author
Forward
0 new messages