Creating a client
Create an entity first, then assign the client role to that entity.
To create a client, first create an entity, then make it play the role of a client.
Before creating a matter for this client, activate it with POST v1/clients/{id}/activate using the shared Send helper.
Duplicate prevention
Section titled “Duplicate prevention”Example
Section titled “Example”This example assumes you have already configured the shared Send helper from the HttpClient recipe.
var entityId = await CreateEntity();
Console.WriteLine($"Created {entityId}");
var clientId = await CreateClient(entityId);
Console.WriteLine($"Created {clientId}");
private static async Task<string?> CreateEntity()
{
var request = new HttpRequestMessage(HttpMethod.Post, "v1/entities") {
Content = new StringContent(
JsonSerializer.Serialize(new {
entityType = "Individual",
firstName = "Gordon",
lastName = "Smith",
currency = "GBP",
email = "gordon.smith@example.com",
}), null, "application/json")
};
return await Send(request, result => {
var data = result.RootElement.GetProperty("data");
return data.GetProperty("id").GetString();
});
}
static async Task<string> CreateClient(string entityId)
{
var request = new HttpRequestMessage(HttpMethod.Post, "v1/clients") {
Content = new StringContent(
JsonSerializer.Serialize(new {
entityId = entityId
}), null, "application/json")
};
return await Send(request, result => {
var data = result.RootElement.GetProperty("data");
return data.GetProperty("id").GetString();
});
}