ConfluenceApiV2Client 1.0.0
See the version list below for details.
dotnet add package ConfluenceApiV2Client --version 1.0.0
NuGet\Install-Package ConfluenceApiV2Client -Version 1.0.0
<PackageReference Include="ConfluenceApiV2Client" Version="1.0.0" />
paket add ConfluenceApiV2Client --version 1.0.0
#r "nuget: ConfluenceApiV2Client, 1.0.0"
// Install ConfluenceApiV2Client as a Cake Addin #addin nuget:?package=ConfluenceApiV2Client&version=1.0.0 // Install ConfluenceApiV2Client as a Cake Tool #tool nuget:?package=ConfluenceApiV2Client&version=1.0.0
Confluence API V2 Client Documentation
Overview
The Confluence API V2 Client is a .NET client for the Confluence REST API v2. It allows users to interact with their Confluence instance programmatically.
GitHub Action
Installation
To install the Confluence API V2 Client library, you can add the package to your project using the .NET CLI or the NuGet Package Manager.
.NET CLI:
dotnet add package ConfluenceApiV2Client --version 1.0.0
NuGet Package Manager:
Install-Package ConfluenceApiV2Client -Version 1.0.0
Supported .NET Versions
The library supports the following .NET versions:
- .NET Standard 2.0
- .NET 6.0
- .NET 7.0
- .NET 8.0
Reference Libraries
The library requires the following NuGet packages:
Microsoft.Extensions.DependencyInjection (Version 8.0.0) Refit (Version 7.0.0) Refit.HttpClientFactory (Version 7.0.0) These dependencies will be installed automatically when you add the ConfluenceApiV2Client package to your project.
Usage
To use the Confluence API V2 Client, you need to authenticate with your Confluence instance using your email and API token. Below are examples demonstrating how to retrieve spaces and pages from your Confluence instance.
Example: Retrieve All Spaces
This example shows how to retrieve all spaces from your Confluence instance.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using ConfluenceApiV2.Client;
using Refit;
internal class Program
{
private static HttpClient Client { get; set; } = null!;
static async Task Main(string[] args)
{
string eMail = "{your-confluence-email}";
string apiToken = "{your-confluence-api-token}";
string auth = $"{eMail}:{apiToken}";
string authBase64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(auth));
Client = RestService.CreateHttpClient("https://{your-domain}.atlassian.net/wiki/api/v2", new RefitSettings());
Client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", authBase64);
var allSpaces = await AllSpacesAsync();
Console.WriteLine($"Spaces Count: {allSpaces.Count}");
foreach (var space in allSpaces)
{
Console.WriteLine($"Space Name: {space.Name}, Space Key: {space.Key}");
}
}
public static async Task<ICollection<SpaceBulk>> AllSpacesAsync()
{
var allSpaces = new List<SpaceBulk>();
try
{
var spacesApi = RestService.For<ISpaceApi>(Client);
string? cursor = null;
do
{
var spacesResult = await spacesApi.GetSpacesAsync(null, null, Type.Global, null, null, null, null, null, null, null, cursor, 25, default);
if (spacesResult.Content == null) break;
allSpaces.AddRange(spacesResult.Content!.Results);
var uri = new UriBuilder(Client.BaseAddress + spacesResult.Content._links.Next);
var queryParams = System.Web.HttpUtility.ParseQueryString(uri.Query);
cursor = queryParams.Get("cursor");
}
while (!string.IsNullOrEmpty(cursor));
return allSpaces;
}
catch (ApiException apiEx)
{
Console.WriteLine($"API Error: {apiEx.StatusCode} - {apiEx.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
return allSpaces;
}
}
Example: Retrieve All Pages of Spaces
This example shows how to retrieve all pages from the spaces in your Confluence instance.
public static async Task<ICollection<PageBulk>> AllPagesOfSpacesAsync(ICollection<SpaceBulk> spaces)
{
var allSpaces = spaces.ToList();
var allPages = new List<PageBulk>();
try
{
var pageApi = RestService.For<IPageApi>(Client);
string? cursor = null;
var ids = allSpaces.Select(s => (long)Convert.ToDouble(s.Id)).ToList();
do
{
var pagesResult = await pageApi.GetPagesAsync(null, ids, null, new[] { Anonymous5.Current }, null, PrimaryBodyRepresentation.Storage, cursor, 25, default);
if (pagesResult.Content == null) break;
allPages.AddRange(pagesResult.Content!.Results);
var uri = new UriBuilder(Client.BaseAddress + pagesResult.Content._links.Next);
var queryParams = System.Web.HttpUtility.ParseQueryString(uri.Query);
cursor = queryParams.Get("cursor");
}
while (!string.IsNullOrEmpty(cursor));
return allPages;
}
catch (ApiException apiEx)
{
Console.WriteLine($"API Error: {apiEx.StatusCode} - {apiEx.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
return allPages;
}
These examples demonstrate basic usage of the Confluence API V2 Client library. Replace placeholders with your actual Confluence email, api-token, and domain.
Additional Information
For more detailed information, refer to the GitHub repository.
Feel free to extend the library or create issues if you encounter any problems. The community and maintainers will be glad to help.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Refit (>= 7.0.0)
- Refit.HttpClientFactory (>= 7.0.0)
-
net6.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Refit (>= 7.0.0)
- Refit.HttpClientFactory (>= 7.0.0)
-
net7.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Refit (>= 7.0.0)
- Refit.HttpClientFactory (>= 7.0.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Refit (>= 7.0.0)
- Refit.HttpClientFactory (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.