I need to read and update the Google Shared Contacts in a G Suite domain using Golang. Since there is no existing Go client library for this API, I'm having to interact with the API at the http level. Presently, I'm stuck on sending the correct Content-Type
header.
Since the documentation at https://developers.google.com/admin-sdk/domain-shared-contacts#Creating says to use application/atom+xml
that was naturally what I tried. However, the response I receive is a 406 Not Acceptable
with a body message of "No acceptable type available". Omitting the Content-Type
returns a 400 "Response contains no content type". Using text/xml
returns a 415 with "Content-Type text/xml is not a valid input type."
req, err := http.NewRequest("POST", href, bytes.NewBuffer([]byte(body)))
if err != nil {
return "", err
}
req.Header.Set("GData-Version", "3.0")
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", "personnel-sync")
req.Header.Set("Content-Type", "text/xml")
resp, err := g.Client.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
log.Println(bodyString)
log.Println(resp.Status)
return bodyString, nil
The body I'm sending is the example in the documentation (link above) but it doesn't seem to matter at this point because an empty body gives the same response.
Barely a minute after posting the question I spotted the problem. Sure enough, it wasn't the Content-Type
header, but the Accept
header. Removing that solved the problem. To be specific, Google was complaining that I requested application/json
as a response type. The Accept
header is apparently not even required.