Ottieni i miei dettagli
In questa sezione richiederemo i dettagli più semplici possibili dall'API Legalesign per verificare che tutto funzioni. Questo esempio visualizzerà i risultati nel terminale.
Esempio da linea di comando
Crea un file chiamato CLIExample.cs nel tuo progetto:
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();
string token = "<token-or-api-key>";
// 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();
}
}
}
Esegui l'esempio
In VS Code, premi Ctrl-F5 o F5. Dovresti vedere qualcosa come:

Se ricevi errori di autenticazione, controlla Autenticarsi con l'API. Se vedi:
{"data":{"user":{"email":"<your-email>","firstName":"Alex","lastName":"Why"}}}
Allora la tua query è stata completata con successo! Potresti notare che non abbiamo specificato un userId — l'oggetto User presume che tu stia parlando di te stesso senza un ID. Se vuoi provare altre query, dai un'occhiata al GraphiQL Explorer.