Async-first .NET client for the GoAffPro API with build-time NSwag generation and polling/event-based change detection.
net8.0net10.0(working on native-AOT compatibility)
dotnet add package GoAffPro.Clientusing GoAffPro.Client;
// Option 1: create from existing token
await using var client = new GoAffProClient(new GoAffProClientOptions
{
BearerToken = "your-access-token",
});
// Option 2: login and create
await using var loggedInClient = await GoAffProClient.CreateLoggedInAsync(
email: "affiliate@example.com",
password: "password123");The wrapper methods are built on top of generated clients:
// Fetch orders with optional time filtering
var orders = await client.GetOrdersAsync(from: DateTimeOffset.UtcNow.AddDays(-1), limit: 50);
// Fetch affiliates with time range
var affiliates = await client.GetAffiliatesAsync(from: startDate, toDate: endDate, limit: 50);
// Fetch payouts and products
var payouts = await client.GetPayoutsAsync(limit: 50);
var products = await client.GetProductsAsync(limit: 50);Wrapper methods return typed models:
GoAffProOrder(includes Subtotal, AffiliateId, Status)GoAffProAffiliate(includes FirstName, LastName, Phone, Country, GroupId)GoAffProReward(includes AffiliateId, Type, Metadata, Level, Status) - currently disabledGoAffProPayoutGoAffProProduct
Each model includes strongly typed fields and RawPayload (JsonElement) for advanced scenarios.
GetRewardsAsync is currently disabled because /user/feed/rewards is returning 404 (observed on 2026-02-18). The method is marked [Obsolete] and returns an empty collection.
var loginResponse = await client.User.UserLoginAsync(new GoAffPro.Client.Generated.User.Body
{
Email = "affiliate@example.com",
Password = "password123",
});
var publicSites = await client.PublicApi.PublicSitesAsync(
site_ids: null,
currency: null,
keyword: null,
limit: 20,
offset: 0);GoAffProEventDetector supports both async streams and classic .NET events. It uses time-based filtering to fetch only new items since the last poll.
using GoAffPro.Client.Events;
var detector = new GoAffProEventDetector(client, pollingInterval: TimeSpan.FromSeconds(30));
// Optional: backfill historical data from a specific time
detector.OrderStartTime = DateTimeOffset.UtcNow.AddDays(-7);
await foreach (var order in detector.NewOrdersAsync(cancellationToken))
{
Console.WriteLine($"New order: {order.Id}");
}using GoAffPro.Client.Events;
var detector = new GoAffProEventDetector(client, pollingInterval: TimeSpan.FromSeconds(30));
detector.OrderDetected += (_, args) => Console.WriteLine($"Order: {args.Order.Id}");
detector.AffiliateDetected += (_, args) => Console.WriteLine($"Affiliate: {args.Affiliate.Id}");
await detector.StartAsync(cancellationToken);The detector stores the last poll timestamp internally. Use OrderStartTime and AffiliateStartTime properties to backfill historical data on first run.
services.AddGoAffProClient(options =>
{
options.BaseUrl = new Uri("https://api.goaffpro.com/v1/", UriKind.Absolute);
options.BearerToken = configuration["GoAffPro:Token"];
options.Timeout = TimeSpan.FromSeconds(30);
});An executable sample is included at:
examples/GoAffPro.Client.Example
Run it with:
dotnet run --project examples/GoAffPro.Client.ExampleOn build, GoAffPro.Client.Generator:
- Fetches
https://api.goaffpro.com/docs/admin/swagger-ui-init.js(or usesopenapi/swagger-ui-init.jsonly if you provide a local override file) - Extracts OpenAPI JSON
- Filters to
/user/*and/public/* - Normalizes schema gaps for generation
- Generates:
src/GoAffPro.Client/Generated/GoAffProUserClient.g.cssrc/GoAffPro.Client/Generated/GoAffProPublicClient.g.cs
Do not edit *.g.cs manually.
dotnet test$env:GOAFFPRO_TEST_TOKEN="your-token"
dotnet test --filter "Category=Integration"The test suite validates generated client method signatures against:
tests/GoAffPro.Client.Tests/Snapshots/GeneratedClientSignatures.snapshot
If generated signatures change, update the snapshot intentionally in the same change.