Sleamhnú go príomh-ábhar

Faigh Mo Shonraí

Sa rannóg seo beidhomar ag iarraidh na sonraí is simplí is féidir ón API Legalesign chun a sheiceáil go bhfuil gach rud ag obair. Déanfaidh an sampla seo na torthaí a thaisceadh isteach sa teirminéal.

Sampla Líne Ordaithe

Cruthaigh comhad darb ainm CLIExample.cs i do thionscadal:

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

Rith an Sampla

I VS Code, brúigh Ctrl-F5 nó F5. Ba cheart duit rud éigin mar seo a fheiceáil:

Sampla rith sa chonsól dífhabhtaithe

Má fhaigheann tú earráidí fíordheimhnithe, seiceáil Fíordheimhniú leis an API. Má fheiceann tú:

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

Ansin tá do cheist críochnaithe go rathúil! B’fhéidir go mbraitheann tú nár shonraigh muid userId — glacann an réad User leis go bhfuil tú ag caint fút féin gan ID. Má tá fonn ort triail a bhaint as ceisteanna eile, seiceáil an GraphiQL Explorer.

Export This Article

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