Skip to main content

Creating Records

Use CreateAsync to create a new entity. It returns the ID of the newly created record.

Create a coworker

var endpoint = new CoworkerEndpoint(client);

var coworker = new Coworker
{
    FullName = "Jane Doe",
    Email = "jane@example.com",
    CoworkerType = eCoworkerRecordType.Individual,
    Businesses = new List<long> { businessId }
};

long newId = await endpoint.CreateAsync(coworker);
Console.WriteLine($"Created coworker with ID: {newId}");

Create a product

var endpoint = new ProductEndpoint(client);

var product = new Product
{
    Name = "Day Pass",
    Business = businessId,
    Currency = currencyId,
    Price = 25.00m
};

long productId = await endpoint.CreateAsync(product);

Error handling

CreateAsync throws InvalidOperationException if the API returns an error — for example, when required fields are missing or validation fails:
try
{
    long id = await endpoint.CreateAsync(entity);
    Console.WriteLine($"Created: {id}");
}
catch (InvalidOperationException ex)
{
    Console.WriteLine($"Creation failed: {ex.Message}");
}