private static async Task GetAccountsAsync() { try { S2SAuthenticationwithD365 s = new S2SAuthenticationwithD365(); string[] accountProperties = { "name" }; JObject collection; ClientCredential credential = new ClientCredential("provide client Id", "provide secret key"); string authorityUri = "https://login.microsoftonline.com/abc.onmicrosoft.com/oauth2/authorize"; // here abc.onmicrosoft.com is my crm domain. Please replace with your domain TokenCache tokenCache = new TokenCache(); AuthenticationContext context = new AuthenticationContext(authorityUri); AuthenticationResult result = await context.AcquireTokenAsync("Provide crm credential", credential); var authToken = result.AccessToken; var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // var response = httpClient.GetAsync("crmurl/api/data/v9.0/accounts?$select=name").Result; var accountJSON = await response.Content.ReadAsStringAsync(); collection = JsonConvert.DeserializeObject <JObject>(response.Content.ReadAsStringAsync().Result); s.DisplayFormattedEntities("Saved query (Active Accounts):", collection, accountProperties); } catch (Exception ex) { Console.WriteLine("Exception ex is" + ex.Message); } }