I am trying to list the users in an office 365 domain. I am using the graph API. I registered my application in azure AD with Directory.Read permissions. I am able to retrieve an access token, but when I try to send a request to list the users it returns an error:
{"odata.error":{"code":"Request_DataContractVersionMissing","message":{"lang":"en",
"value":"The specified api-version is invalid. The value must exactly match a supported
version."}}}
This is the request I make:
apiUrl := "https://graph.windows.net/"
resource := "vstoregrid.com/users"
data := url.Values{}
data.Set("api-version", "2013-04-05")
authbear := "Bearer "
authbear += accessobj.Access_token
u, _ := url.ParseRequestURI(apiUrl)
u.Path = resource
urlStr := fmt.Sprintf("%v", u)
client := &http.Client{}
r, _ := http.NewRequest("GET", urlStr, bytes.NewBufferString(data.Encode()))
r.Header.Add("Content-Type", "application/json")
r.Header.Set("Authorization", authbear)
r.Header.Add("Host", "graph.windows.net")
r.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
I am using the version as specified in the documentation. Where am I going wrong?