![]() |
VOOZH | about |
dotnet add package Endjin.FreeAgent.Client --version 1.0.7
NuGet\Install-Package Endjin.FreeAgent.Client -Version 1.0.7
<PackageReference Include="Endjin.FreeAgent.Client" Version="1.0.7" />
<PackageVersion Include="Endjin.FreeAgent.Client" Version="1.0.7" />Directory.Packages.props
<PackageReference Include="Endjin.FreeAgent.Client" />Project file
paket add Endjin.FreeAgent.Client --version 1.0.7
#r "nuget: Endjin.FreeAgent.Client, 1.0.7"
#:package Endjin.FreeAgent.Client@1.0.7
#addin nuget:?package=Endjin.FreeAgent.Client&version=1.0.7Install as a Cake Addin
#tool nuget:?package=Endjin.FreeAgent.Client&version=1.0.7Install as a Cake Tool
A comprehensive .NET client library for the FreeAgent accounting API, providing strongly-typed access to all FreeAgent resources.
Install via NuGet Package Manager:
dotnet add package Endjin.FreeAgent.Client
Or via Package Manager Console:
Install-Package Endjin.FreeAgent.Client
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",
// Set to true to use the FreeAgent Sandbox environment (https://signup.sandbox.freeagent.com)
UseSandbox = true
};
// 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();
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 = new Uri("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");
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:
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
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}");
}
For complete API documentation, visit the FreeAgent API Documentation.
We welcome contributions! Please feel free to submit issues and pull requests.
This project is licensed under the Apache License 2.0 - see the file for details.
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 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
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. |
This package is not used by any popular GitHub repositories.