← ALL POSTS
22 NOVEMBER 2025

C# Code Examples

using Aiva.Sdk;

var client = new AivaClient(
    apiKey: Environment.GetEnvironmentVariable("AIVA_API_KEY"),
    merchantId: Environment.GetEnvironmentVariable("AIVA_MERCHANT_ID")
);

// Get subscriptions and calculate MRR
var subscriptions = await client.Subscriptions.ListAsync(status: "active");

decimal mrr = subscriptions.Items
    .Sum(sub => sub.Interval == "year" ? sub.Price / 12 : sub.Price);

decimal arr = mrr * 12;

Console.WriteLine($"MRR: ${mrr:F2}");
Console.WriteLine($"ARR: ${arr:F2}");
Console.WriteLine($"Active Subscriptions: {subscriptions.Total}");

// Get at-risk customers and send messages
var atRisk = await client.Customers.ListAsync(segment: "At Risk");

foreach (var customer in atRisk.Items.Take(10))
{
    await client.Aiva.SendMessageAsync(new SendMessageRequest
    {
        CustomerEmail = customer.Email,
        CustomerName = $"{customer.FirstName} {customer.LastName}",
        Message = "We miss you! Here's 20% off.",
        Channel = MessageChannel.Email
    });
}

Install:

dotnet add package Aiva.Sdk
`"
Want this working on your store? Aiva does the sales, marketing and service work - in your voice, around the clock.
Get Aiva