4

While adding contacts using google contacts api, I have been getting status code 400, with Invalid XML Document error.

If I remove the following line the add contact api succeeds. However, this behaviour is not what I want. I would like to add it to the base group 6.

<gContact:groupMembershipInfo deleted="false"
          href="http://www.google.com/m8/feeds/groups/binthi123@gmail.com/base/6"/>

The following is the body of the add new contact api post request:

<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>1234567890</gd:givenName>
  </gd:name>
  <gd:phoneNumber rel="http://schemas.google.com/g/2005#mobile" primary="true">
    ${phone_number}
  </gd:phoneNumber>
  <gContact:groupMembershipInfo deleted="false" href="http://www.google.com/m8/feeds/groups/binthi123@gmail.com/base/6" />
</atom:entry>
barbsan
  • 3,418
  • 11
  • 21
  • 28
Vinthi
  • 41
  • 1
  • have you tried adding `xmlns:gContact="http://schemas.google.com/contact/2008"` to `atom:entry` tag? – barbsan Nov 29 '18 at 09:38
  • 1
    Same is happening to me. Seems like google has just changed something in the API without updating the docs... Have you found a solution? The gContact:groupMembershipInfo has worked for years until a few hours ago. @barbsan the addition of `xmlns:gContact="http://schemas.google.com/contact/2008"` does not solve the problem – Milk Man Nov 29 '18 at 22:06

2 Answers2

5

I solved the problem changing the tag <gContact:groupMembershipInfo>in <gd:groupMembershipInfo> , so any tag with <gContact> no longer works but only with <gd:>, this only when you create new contact if you update there isn't any problem

JohnJ
  • 51
  • 2
  • 1
    Worked perfectly. Suggested that this be the accepted answer. How did you find the solution John? – Milk Man Dec 04 '18 at 01:32
  • 2
    Hi @MilkMan, for logical deduction because I've two function one for create new contact and another one for update , the problem was only in the first one ,so removing one tag at a time I've found that the problem was on tag and then I've tried to subsitute with and was ok,but on Google guide hasn't been updated. – JohnJ Dec 05 '18 at 06:07
  • @JohnJ I applied above solution but it's still not working for me. Can you help me ? – Nency Dec 13 '18 at 05:13
  • just change the opening tag to only? what about the ending tag does it required as well? – gumuruh Sep 18 '19 at 01:52
2

Our team ran into a variant of this problem where the Contacts API was returning "Invalid JSON" 400 error when posting a new contact (via XML). The problem was related to us setting the alt=json parameter; apparently there is a bug on Google's end that gets invoked if you ask for a JSON response from that method.

Ryan
  • 71
  • 3