Get My Details
In this section we're going to request the simplest details possible from the Legalesign API to check that everything is working. This example will dump the results into the terminal.
Command Line Example
Create a file called CLIExample.cs in your project:
CLIExample.cs
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
namespace CLILegalesignExamples
{
class CLILegalQLExample
{
static async Task Main(string[] args)
{
Console.WriteLine("Legalesign C# Command Line Example");
var httpClient = new HttpClient();
// Get an access token
string token = await GetTokenAsync(httpClient);
// Set up the GraphQL client
httpClient.BaseAddress = new Uri("https://graphql.uk.legalesign.com/graphql");
httpClient.DefaultRequestHeaders.Add("User-Agent", "LegalesignCLI");
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var queryObject = new
{
query = @"query {
user {
email
firstName
lastName
}
}",
variables = new { }
};
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
Content = new StringContent(JsonSerializer.Serialize(queryObject), Encoding.UTF8, "application/json")
};
using (var response = await httpClient.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var responseString = await response.Content.ReadAsStringAsync();
if (responseString != null)
{
Console.WriteLine(responseString);
}
}
Console.ReadLine();
}
static async Task<string> GetTokenAsync(HttpClient httpClient)
{
var requestBody = new
{
AuthFlow = "USER_PASSWORD_AUTH",
ClientId = "<your-client-id>",
AuthParameters = new
{
USERNAME = "<your-username>",
PASSWORD = "<your-password>"
}
};
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://cognito-idp.eu-west-2.amazonaws.com"),
Content = new StringContent(JsonSerializer.Serialize(requestBody), Encoding.UTF8, "application/x-amz-json-1.1")
};
request.Headers.Add("X-Amz-Target", "AWSCognitoIdentityProviderService.InitiateAuth");
var response = await httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
var doc = JsonSerializer.Deserialize<JsonElement>(json);
return doc.GetProperty("AuthenticationResult").GetProperty("AccessToken").GetString()!;
}
}
}
Run the Example
In VS Code, press Ctrl-F5 or F5. You should see something like:

If you receive authentication errors, check your credentials. If you see:
{"data":{"user":{"email":"<your-email>","firstName":"Alex","lastName":"Why"}}}
Then your query has completed successfully! You might notice we didn't specify a userId — the User object assumes you are talking about yourself without an ID. If you're keen to try other queries, check out the GraphiQL Explorer.