Leum gu prìomh susbaint

Faigh Mo Fiosrachadh

Anns an earrainn seo tha sinn a’ dol a dh’iarrtas na mion-fhiosrachaidh as sìmplidhe comasach bhon Legalesign API gus faicinn gu bheil a h-uile càil ag obair. Bidh an eisimpleir seo a’ cur an toradh dhan terminal.

Eisimpleir Loidhne-àithne

Cruthaich faidhle ris an canar CLIExample.cs anns a’ phròiseact agad:

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

Ruith an Eisimpleir

Anns an VS Code, brùth Ctrl-F5 no F5. Bu chòir dhut rudeigin coltach ri:

Cur an gnìomh samplach anns a’ chonsol debug

Ma gheibh thu mearachdan dearbhaidh, thoir sùil air Dearbhaich leis an API. Ma chì thu:

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

An uair sin tha do cheist air a choileanadh gu soirbheachail! Is dòcha gun tuigs thu nach do shònraich sinn userId — tha am pàirt User a’ gabhail ris gu bheil thu a’ bruidhinn mu do dheidhinn fhèin gun ID. Ma tha thu airson feuchainn ri ceistean eile, thoir sùil air an GraphiQL Explorer.

Export This Article

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