Endjin.FreeAgent.Client
1.0.5
See the version list below for details.
dotnet add package Endjin.FreeAgent.Client --version 1.0.5
NuGet\Install-Package Endjin.FreeAgent.Client -Version 1.0.5
<PackageReference Include="Endjin.FreeAgent.Client" Version="1.0.5" />
<PackageVersion Include="Endjin.FreeAgent.Client" Version="1.0.5" />
<PackageReference Include="Endjin.FreeAgent.Client" />
paket add Endjin.FreeAgent.Client --version 1.0.5
#r "nuget: Endjin.FreeAgent.Client, 1.0.5"
#:package Endjin.FreeAgent.Client@1.0.5
#addin nuget:?package=Endjin.FreeAgent.Client&version=1.0.5
#tool nuget:?package=Endjin.FreeAgent.Client&version=1.0.5
Endjin.FreeAgent.Client
A comprehensive .NET client library for the FreeAgent accounting API, providing strongly-typed access to all FreeAgent resources.
Features
- Strongly-typed models for all FreeAgent API resources
- Modern .NET 10 implementation with C# 14 features
- Async/await support throughout
- Built-in caching for improved performance
- OAuth2 authentication support
- Comprehensive resource coverage including:
- Invoices and Credit Notes
- Contacts and Projects
- Expenses and Bills
- Bank Accounts and Transactions
- Timeslips and Tasks
- VAT Returns
- Users and Company settings
- And much more...
Installation
Install via NuGet Package Manager:
dotnet add package Endjin.FreeAgent.Client
Or via Package Manager Console:
Install-Package Endjin.FreeAgent.Client
Quick Start
Configuration
using Endjin.FreeAgent.Client;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
// Configure services
ServiceCollection services = new();
services.AddMemoryCache();
services.AddHttpClient();
services.AddLogging();
// Configure FreeAgent options
FreeAgentOptions options = new()
{
ClientId = "your-client-id",
ClientSecret = "your-client-secret",
RefreshToken = "your-refresh-token"
};
// Create client
ServiceProvider serviceProvider = services.BuildServiceProvider();
IMemoryCache cache = serviceProvider.GetRequiredService<IMemoryCache>();
IHttpClientFactory httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
ILoggerFactory loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
FreeAgentClient client = new(options, cache, httpClientFactory, loggerFactory);
await client.InitializeAndAuthorizeAsync();
Basic Usage
using Endjin.FreeAgent.Domain;
// Get all active projects
IEnumerable<Project> projects = await client.Projects.GetAllActiveAsync();
// Get all contacts
IEnumerable<Contact> contacts = await client.Contacts.GetAllAsync();
// Create an invoice
Invoice invoice = new()
{
Contact = "https://api.freeagent.com/v2/contacts/123",
DatedOn = DateOnly.FromDateTime(DateTime.Now),
PaymentTermsInDays = 30,
InvoiceItems = new List<InvoiceItem>
{
new()
{
Description = "Consulting Services",
ItemType = "Services",
Quantity = 1,
Price = 1000.00m
}
}
};
Invoice createdInvoice = await client.Invoices.CreateAsync(invoice);
// Get timeslips for a project
IEnumerable<Timeslip> timeslips = await client.Timeslips.GetByProjectUrlAsync("https://api.freeagent.com/v2/projects/456");
Advanced Features
Interactive OAuth2 Login
The easiest way to get your initial access and refresh tokens is to use the interactive login helper:
using Endjin.FreeAgent.Client.OAuth2;
using Microsoft.Extensions.Logging;
// Configure OAuth2 options (only need ClientId and ClientSecret)
OAuth2Options options = new()
{
ClientId = "your-client-id",
ClientSecret = "your-client-secret",
UsePkce = true
};
// Create HTTP client and logger
using var httpClient = new HttpClient();
using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
var logger = loggerFactory.CreateLogger<InteractiveLoginHelper>();
// Create and use the interactive login helper
var loginHelper = new InteractiveLoginHelper(options, httpClient, logger);
InteractiveLoginResult result = await loginHelper.LoginAsync(redirectPort: 5000);
// Save the refresh token for future use
Console.WriteLine($"Refresh Token: {result.RefreshToken}");
The LoginAsync method will:
- Start a local HTTP listener
- Open your browser to the FreeAgent authorization page
- Wait for the OAuth callback
- Exchange the authorization code for tokens
- Return both access and refresh tokens
Caching
The client includes built-in memory caching with configurable expiration:
// Cache is automatically used for GET operations
IEnumerable<Project> projects1 = await client.Projects.GetAllAsync(); // Fetches from API
IEnumerable<Project> projects2 = await client.Projects.GetAllAsync(); // Returns cached result
Error Handling
The client provides detailed error information for API failures:
try
{
Invoice invoice = await client.Invoices.GetByIdAsync("invalid-id");
}
catch (HttpRequestException ex)
{
// Handle API errors
Console.WriteLine($"API Error: {ex.Message}");
}
Requirements
- .NET 10.0 or later
- FreeAgent API credentials (Client Id and Client Secret)
- Active FreeAgent account
- For first-time setup, you can use interactive login to obtain a refresh token
Documentation
For complete API documentation, visit the FreeAgent API Documentation.
Contributing
We welcome contributions! Please feel free to submit issues and pull requests.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Support
For support, please contact Endjin Limited or raise an issue on our GitHub repository.
Copyright (c) Endjin Limited. All rights reserved.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Corvus.Retry (>= 1.0.7)
- Duende.IdentityModel (>= 7.1.0)
- Endjin.FreeAgent.Domain (>= 1.0.5)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Caching.Memory (>= 10.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Http (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Endjin.FreeAgent.Client:
| Package | Downloads |
|---|---|
|
Endjin.FreeAgent.Client.Extensions
Extension methods and additional functionality for the Endjin.FreeAgent.Client library, providing timesheets management, project filtering, user settings, and activity summaries. |
GitHub repositories
This package is not used by any popular GitHub repositories.