Skip to content

Instantly share code, notes, and snippets.

@iaintshine
Created May 13, 2015 09:43
Show Gist options
  • Save iaintshine/e16a8e568354a2502b71 to your computer and use it in GitHub Desktop.
Save iaintshine/e16a8e568354a2502b71 to your computer and use it in GitHub Desktop.
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace basecrmcsharp
{
class MainClass
{
public static void Main (string[] args)
{
ShowUser ().Wait ();
}
static async Task ShowUser()
{
using (var client = new HttpClient ())
{
client.BaseAddress = new Uri ("https://api.getbase.com");
// the API v2 responds with JSON
client.DefaultRequestHeaders.Accept.Clear ();
client.DefaultRequestHeaders.Accept.Add (new MediaTypeWithQualityHeaderValue ("application/json"));
// the API V2 requires the User-Agent header to be set
client.DefaultRequestHeaders.Add ("User-Agent", "BaseCRM/V2 CSharp");
// the API V2 uses OAuth 2 Bearer Authorization schema
client.DefaultRequestHeaders.Add ("Authorization", "Bearer " + AccessToken());
HttpResponseMessage response = await client.GetAsync ("/v2/users/self");
if (response.IsSuccessStatusCode) {
Console.WriteLine (await response.Content.ReadAsStringAsync ());
}
}
}
static String AccessToken()
{
return Environment.GetEnvironmentVariable ("BASECRM_ACCESS_TOKEN");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment