Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using(var httpClient = new HttpClient())
// Set headers
httpClient.Timeout = new TimeSpan(0, 2, 0); // 2 minutes
httpClient.BaseAddress = new Uri(_serviceUrl);
httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
new MediaTypeWithQualityHeaderValue("application/json"));
// Use the bearer token here
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResponse.Token);
HttpResponseMessage whoAmIResponse = await httpClient.GetAsync("api/data/v9.1/WhoAmI()");
Guid userId;
if (whoAmIResponse.IsSuccessStatusCode)
var jWhoAmIResponse = JObject.Parse(whoAmIResponse.Content.ReadAsStringAsync().Result);
// Finally, Get the userId
userId = (Guid)jWhoAmIResponse["UserId"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment