0

I am trying to POST contact data to GContact to create a new contact. I can create a new contact if I use only "gd" XML elements, but when I try and post a "gContact" element it gives me an error. I'm sure it's something simple because I am a total amateur, but I would appreciate any help.

This works

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<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>Jack</gd:givenName>
        <gd:familyName>Masters</gd:familyName>
        <gd:fullName>Jack Masters</gd:fullName>
        <gd:additionalName>Rascal</gd:additionalName>
        <gd:namePrefix>Sir</gd:namePrefix>
        <gd:nameSuffix>II</gd:nameSuffix>
    </gd:name>
    <atom:content type="text">These are some testing notes.</atom:content>
    <gd:email rel="http://schemas.google.com/g/2005#work" address="newtestAddress@gmail.com" primary="true" />
    <gd:phoneNumber rel="http://schemas.google.com/g/2005#home" primary="true">716-999-0098</gd:phoneNumber>
    <gd:phoneNumber rel="http://schemas.google.com/g/2005#work">666-8765-9087</gd:phoneNumber>
    <gd:structuredPostalAddress rel="http://schemas.google.com/g/2005#home">
        <gd:formattedAddress>3546 Madison Street, Chicago IL, 56879</gd:formattedAddress>
        <gd:street>3546 Madison Street</gd:street>
        <gd:city>Chicago</gd:city>
        <gd:state>IL</gd:state>
        <gd:country>USA</gd:country>
    </gd:structuredPostalAddress>
</atom:entry>

But this doesn't

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<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>Jack</gd:givenName>
        <gd:familyName>Masters</gd:familyName>
        <gd:fullName>Jack Masters</gd:fullName>
        <gd:additionalName>Rascal</gd:additionalName>
        <gd:namePrefix>Sir</gd:namePrefix>
        <gd:nameSuffix>II</gd:nameSuffix>
    </gd:name>
    <atom:content type="text">These are some testing notes.</atom:content>
    <gd:email rel="http://schemas.google.com/g/2005#work" address="newtestAddress@gmail.com" primary="true" />
    <gd:email rel="http://schemas.google.com/g/2005#home" address="evenNewerAddress@yahoo.com" />
    <gd:phoneNumber rel="http://schemas.google.com/g/2005#home" primary="true">716-999-0098</gd:phoneNumber>
    <gd:phoneNumber rel="http://schemas.google.com/g/2005#work">666-8765-9087</gd:phoneNumber>
    <gd:structuredPostalAddress rel="http://schemas.google.com/g/2005#home">
        <gd:formattedAddress>3546 Madison Street, Chicago IL, 56879</gd:formattedAddress>
        <gd:street>3546 Madison Street</gd:street>
        <gd:city>Chicago</gd:city>
        <gd:state>IL</gd:state>
        <gd:country>USA</gd:country>
    </gd:structuredPostalAddress>
    <gContact:groupMembershipInfo href="http://www.google.com/m8/feeds/groups/default/base/14b3e56788eb41b8" />
</atom:entry>

I have tried a number of different gContact elements and nothing seems to work. I get a 400 HTTP response code every time.

This is the response detail. I can't seem to figure where the error is.

Optional(<NSHTTPURLResponse: 0x600000234480> { URL: https://www.google.com/m8/feeds/contacts/default/full?alt=json } { status code: 400, headers {
    "Cache-Control" = "private, max-age=0";
    "Content-Encoding" = gzip;
    "Content-Type" = "text/plain; charset=UTF-8";
    Date = "Tue, 07 Mar 2017 16:02:17 GMT";
    Expires = "Tue, 07 Mar 2017 16:02:17 GMT";
    Server = GSE;
    "alt-svc" = "quic=\":443\"; ma=2592000; v=\"36,35,34\"";
    "x-content-type-options" = nosniff;
    "x-frame-options" = SAMEORIGIN;
    "x-xss-protection" = "1; mode=block"; } })
Flightfire
  • 61
  • 1
  • 4

2 Answers2

0

You may want to try these recommended actions for error code 400 as given in Standard Error Responses:

  • invalidParameter

    Do not retry without fixing the problem. You need to provide a valid value for the parameter specified in the error response.

  • badRequest

    Do not retry without fixing the problem. You need to make changes to the API query in order for it to work.

You may want to also check this related SO post for additional insights that might help you.

Community
  • 1
  • 1
Teyam
  • 7,686
  • 3
  • 15
  • 22
0

I figured it out. I was literally formatting every gContact element that I was trying incorrectly. I had tried 4 separate things and wrongly assumed it was something contextual I hadn't set. In reality I had formatted all four wrong in different ways. New programmer lesson learned.

Flightfire
  • 61
  • 1
  • 4