Hello Jake, Your code looks quite complicated and if you are writing an application in Java, you shouldn't have to construct the XML and send an explicit HTTP POST request which seems to be missing the authorization header. Please have a look at the Contacts API Java developers' guide<http://code.google.com/apis/contacts/docs/3.0/developers_guide_java.html#Creating>which explain how to create a contact using the Java client library.
Creating a Domain Shared Contacts is a similar process with a difference in the POST URL which should be (as you mentioned in your message): https://www.google.com/m8/feeds/contacts/<domain>/full <https://www.google.com/m8/feeds/contacts/%3Cdomain%3E/full>I hope this helped! Best, Alain On Mon, May 23, 2011 at 2:30 PM, Jake L. <[email protected]> wrote: > I am developing a program for my institution to create shared contacts on > our domain and I have run into a problem. > > I'm not sure what part of my code is making the server return this error, > but the error is: > > Java.io.IOException: Server returned HTTP response code: 400 for URL: > https://www.google.com/m8/feeds/contacts/<domain>/full > > Here is my code: > > //Code begins here > > String line, data; > data = > > <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' /> <gd:name> > <gd:givenName>" > > + itemFirstName + "</gd:givenName> <gd:familyName>" + itemLastName + > "</gd:familyName> > <gd:fullName>" + itemFirstName + " " + itemLastName + "</gd:fullName> > </gd:name> <gd:email rel='http://schemas.google.com/g/2005#work' > primary='true' address='" + *itemEmail* + "' displayName='" + > itemFirstName + " " + itemLastName+ "' /> <gd:phoneNumber rel=' > http://schemas.google.com/g/2005#work' primary='true'>" + itemPhone + > "</gd:phoneNumber> > <gd:organization><gd:orgTitle>" + itemTitle + > "</gd:orgTitle><gd:orgDepartment>" + itemDept + > "</gd:orgDepartment></gd:organization> > </atom:entry> > > URL url = > > *new* URL("https://www.google.com/m8/feeds/contacts/<domain>/thin"); > > HttpURLConnection conn = (HttpURLConnection) url.openConnection(); > > conn.setDoOutput( > > *true*); > > conn.setRequestMethod( > > "POST"); > > conn.setRequestProperty( > > "Content-Type", "application/atom+xml"); > > conn.setRequestProperty( > > "Authorization","GoogleLogin auth=<code here>"); > > conn.setRequestProperty( > > "GData-Version","3.0"); > > OutputStreamWriter writer = > > *new* OutputStreamWriter(conn.getOutputStream()); > > //write parameters > > writer.write(data); > > writer.flush(); > > StringBuffer answer = > > *new* StringBuffer(); > > BufferedReader reader = > > *new* BufferedReader(*new* InputStreamReader(conn.getInputStream())); > > *while* ((line = reader.readLine()) != *null*) > > answer.append(line); > > writer.close(); > > reader.close(); > > System. > > *out*.println(conn.getResponseCode()); > > System. > > *out*.println(conn.getResponseMessage()); > > } > > *catch* (MalformedURLException ex) { > > ex.printStackTrace(); > > } > > *catch* (IOException ex) { > > ex.printStackTrace(); > } > > // Code ends here > > I am posting a string to the server, its in xml format with tags and > everything. I'm not sure what I am doing wrong... Is it allowed to post a > string as xml? > > Thank you. > Jake > > -- > You received this message because you are subscribed to the Google > Groups "Google Contacts, Shared Contacts and User Profiles APIs" group. > To post to this group, send email to > [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://code.google.com/apis/contacts/community/forum.html > > -- Alain Vongsouvanh -- You received this message because you are subscribed to the Google Groups "Google Contacts, Shared Contacts and User Profiles APIs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://code.google.com/apis/contacts/community/forum.html
