ChatWootApi.Extensions 0.9.7

dotnet add package ChatWootApi.Extensions --version 0.9.7
                    
NuGet\Install-Package ChatWootApi.Extensions -Version 0.9.7
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ChatWootApi.Extensions" Version="0.9.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ChatWootApi.Extensions" Version="0.9.7" />
                    
Directory.Packages.props
<PackageReference Include="ChatWootApi.Extensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ChatWootApi.Extensions --version 0.9.7
                    
#r "nuget: ChatWootApi.Extensions, 0.9.7"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ChatWootApi.Extensions@0.9.7
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ChatWootApi.Extensions&version=0.9.7
                    
Install as a Cake Addin
#tool nuget:?package=ChatWootApi.Extensions&version=0.9.7
                    
Install as a Cake Tool

ChatWootApi.Extensions

English | 简体中文

Dependency-injection extensions for ChatWootApi. This package registers Refit clients, configures the Chatwoot base address, and automatically adds the api_access_token request header for Application and Platform APIs.

Installation

dotnet add package ChatWootApi.Extensions

This package transitively references the core ChatWootApi package, so most applications do not need to install the core package separately.

Configuration option 1: IConfiguration

appsettings.json:

{
  "ChatWootApi": {
    "BaseAddress": "https://app.chatwoot.com/",
    "AccountAccessToken": "your-account-access-token",
    "PlatformAccessToken": "your-platform-access-token"
  }
}

Register the API groups you need during application startup:

using ChatWootApi.Extensions;

builder.Services.AddChatWootApplicationApi(builder.Configuration);
builder.Services.AddChatWootClientApi(builder.Configuration);
builder.Services.AddChatWootPlatformApi(builder.Configuration);

The default configuration section name is ChatWootApi. You can use another section name when needed:

builder.Services.AddChatWootApplicationApi(
    builder.Configuration,
    sectionName: "Services:Chatwoot");

Configuration option 2: delegate

builder.Services.AddChatWootApplicationApi(options =>
{
    options.BaseAddress = "https://chatwoot.example.com/";
    options.AccountAccessToken = "your-account-access-token";
});

builder.Services.AddChatWootPlatformApi(options =>
{
    options.BaseAddress = "https://chatwoot.example.com/";
    options.PlatformAccessToken = "your-platform-access-token";
});

HTTP request and response logging

Logging is disabled by default. Set EnableLogging to enable logging for every registered Chatwoot API client:

{
  "ChatWootApi": {
    "BaseAddress": "https://app.chatwoot.com/",
    "EnableLogging": true,
    "IncludeBodyInLogs": false
  }
}

To log only selected API interfaces, leave EnableLogging false and configure LoggingApiNames:

{
  "ChatWootApi": {
    "LoggingApiNames": [
      "IApplicationContactsApi",
      "ChatWootApi.Platform.IPlatformAccountApi"
    ]
  }
}

LoggingApiNames accepts either an API interface short name or its full type name. The handler logs the HTTP method, redacted URI, headers, status code, and duration. Request and response bodies are omitted unless IncludeBodyInLogs is enabled. Access tokens, authorization/cookie headers, sensitive query parameters, and common sensitive JSON/form fields are masked before logging; unsupported or oversized bodies are omitted.

The package uses Microsoft.Extensions.Logging; configure the logging provider and level in the host application as usual.

Calling APIs

After registration, inject a specific API interface:

using ChatWootApi.Application;

app.MapGet("/contacts", async (
    long accountId,
    IApplicationContactsApi contactsApi,
    CancellationToken cancellationToken) =>
{
    return await contactsApi.ContactListAsync(accountId, cancellationToken);
});

Application API also provides an aggregate interface:

app.MapGet("/account", async (
    long accountId,
    IChatWootApplicationApi chatwoot,
    CancellationToken cancellationToken) =>
{
    return await chatwoot.GetAccountDetailsAsync(accountId, cancellationToken);
});

Available registration methods:

  • AddChatWootApplicationApi: registers Application API and uses Account access tokens.
  • AddChatWootClientApi: registers public Client API and does not add an access token.
  • AddChatWootPlatformApi: registers Platform API and uses Platform access tokens.

Temporarily switching Application API access tokens

Application API api_access_token values are usually user-level tokens. The default AccessTokenProvider supports a temporary Application access token scoped to the current async flow. When the scope is disposed, the previous outer token or configured AccountAccessToken is restored.

using ChatWootApi.Application;
using ChatWootApi.Extensions;

app.MapGet("/contacts", async (
    long accountId,
    string userAccessToken,
    AccessTokenProvider accessTokenProvider,
    IApplicationContactsApi contactsApi,
    CancellationToken cancellationToken) =>
{
    using var applicationAccessToken = accessTokenProvider.UseApplicationAccessToken(userAccessToken);

    return await contactsApi.ContactListAsync(accountId, cancellationToken);
});

Nested calls restore the outer token after the inner using is disposed. Platform API always uses PlatformAccessToken and is not affected by Application token scopes. If AccountAccessToken is not configured and there is no active Application token scope, Application API calls throw InvalidOperationException.

Custom IAccessTokenProvider

If tokens must come entirely from tenant or request context, implement IAccessTokenProvider and register it before calling the Chatwoot registration extensions:

using ChatWootApi;
using ChatWootApi.Extensions;

builder.Services.AddSingleton<IAccessTokenProvider, TenantAccessTokenProvider>();
builder.Services.AddChatWootApplicationApi(builder.Configuration);
builder.Services.AddChatWootPlatformApi(builder.Configuration);

The extensions register the default provider with TryAddSingleton, so an existing custom implementation is preserved. Each request asks for a token by AccessTokenKind.Account or AccessTokenKind.Platform.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.9.7 110 7/23/2026
0.9.6 103 7/23/2026
0.9.5 98 7/23/2026
0.9.4 105 7/13/2026
0.9.3 102 7/13/2026
0.9.2 97 7/13/2026
0.9.1 106 7/13/2026
0.9.0 99 7/13/2026
0.8.0 110 7/10/2026
0.7.1 106 7/10/2026
0.7.0 107 7/10/2026
0.6.0 113 7/9/2026
0.4.0 110 7/7/2026
0.3.0 103 7/6/2026
0.2.0 113 7/6/2026
0.1.0 108 7/2/2026