Skip to main content

.NET Integration

.NET usage info and examples


Use a dedicated nuget package to integrate XRAY without using GraphQL. Everything is generated and ready to use.

Before start using this package, register and get a unique API Access Token.

Usage info

To use XRayApiClient provide it with a URL endpoint and token.

An endpoint is a URL where GraphQL schema is exposed - https://api.xray.tangoaml.com/graphql.
A token is a secret key generated on the portal and is unique to your organization.

To use APIs first authenticate the client using the AuthenticateWithAsync method. It will use the provided token to get XRAY's access token - which lasts usually 30min. After the token expires, authenticate again with the same Token.

After authentication, use XRayApiClient to create and retrieve sessions. Set isTesting = true on the session to use free test data.

Examples

Creating session

The returned session is populated with small a subset of data - to get details, use GetSessionDetails().

static async Task<Session> CreateTestSession_PersonPasses()
{
using var client = new XRayApiClient(Endpoint);
await client.AuthenticateWithAsync(Token);
Session session;

try
{
session = await client
.SetPerson(new PersonInput()
{
FirstName = "John",
MiddleName = "Henry",
LastName = "Smith",
Gender = "male",
IsoLatin1Name = "Johnny",
Nationality = "AU",
Dob = DateTime.Parse("2000-03-03"),
Documents = new List<DocumentInput>() {
new DocumentInput { Number = "B23SDS2233", Expiry = DateTime.Parse("2022-03-03"), Type = DocumentType.MediCard }
},
Communications = new List<CommunicationInput>() {
new CommunicationInput { IpAddress = "22.22.22.22", Website = "www.johnsmith.com" }
},
})
.SetIsTesting(true)
.SetResponseTransport(ResponseTransport.LongPolling)
//.SetWebhook("https://en4f7tfoezabp.x.pipedream.net/")
.SetDescription("Test from code: " + DateTime.Now.ToString())
.SetConfigurationId(ConfigurationId)
.PublishAsync();
}
catch (ResponseException resExc)
{
Console.WriteLine(resExc.Message);
Console.WriteLine(String.Join("\n", resExc.AllErrorMessages));
return null;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}

// Now get all details about the session
return await GetSessionDetails(session.Id ?? Guid.Empty, client);
}

Get Session details

        static async Task<Session> GetSessionDetails(Guid id, XRayApiClient client)
{
try
{
var session = await client.GetSessionAsync(id);
Console.WriteLine(JsonSerializer.Serialize(session, new JsonSerializerOptions { WriteIndented = true }));

return session;
}
catch (ResponseException resExc)
{
Console.WriteLine(resExc.Message);
Console.WriteLine(String.Join("\n", resExc.AllErrorMessages));
return null;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}