Neidio i’r prif gynnwys

Get My Details

Yn yr adran hon byddwn yn ceisio’r manylion symlaf posibl o'r Legalesign API i wirio bod popeth yn gweithio. Bydd y sampl hon yn dangos y canlyniadau yn y terminal.

Command Line Example

Creu ffeil o’r enw CLIExample.cs yn eich prosiect:

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();
}
}
}

Run the Example

Yn VS Code, pwyswch Ctrl-F5 neu F5. Dylech weld rhywbeth fel:

Sample execution in the debug console

Os cewch wallau awdurdodi, gwiriwch Authenticate with the API. Os gwelwch:

{"data":{"user":{"email":"<your-email>","firstName":"Alex","lastName":"Why"}}}

Yna mae eich ymholiad wedi’i gwblhau’n llwyddiannus! Efallai y sylwch nad oeddem yn nodi userId — mae'r gwrthrych User yn tybio eich bod yn siarad amdanoch chi eich hun heb ID. Os ydych am geisio ymholiadau eraill, edrychwch ar y GraphiQL Explorer.

Export This Article

Save a copy of this page as PDF or plain text.