Creating a client
Create an entity first, then assign the client role to that entity.
Flow
To create a client, first create an entity, then make it play the role of a client.
Duplicate prevention
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 = "AUD",
email = "john.smith@domain.local",
}), 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();
});
}