ConfluenceApiV2Client 1.0.6

dotnet add package ConfluenceApiV2Client --version 1.0.6                
NuGet\Install-Package ConfluenceApiV2Client -Version 1.0.6                
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="ConfluenceApiV2Client" Version="1.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ConfluenceApiV2Client --version 1.0.6                
#r "nuget: ConfluenceApiV2Client, 1.0.6"                
#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.
// Install ConfluenceApiV2Client as a Cake Addin
#addin nuget:?package=ConfluenceApiV2Client&version=1.0.6

// Install ConfluenceApiV2Client as a Cake Tool
#tool nuget:?package=ConfluenceApiV2Client&version=1.0.6                

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

ci

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

NuGet Package Manager:

Install-Package ConfluenceApiV2Client

Supported .NET Versions

The library supports the following .NET versions:

  • .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.

  • Minver (version 5.0.0) - A minimalist .NET package for versioning .NET SDK-style projects using Git tags.

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 Compatible and additional computed target framework versions.
.NET 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. 
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
1.0.6 199 5/22/2024
1.0.5 121 5/21/2024
1.0.4 123 5/20/2024
1.0.3 114 5/19/2024
1.0.1 115 5/18/2024
1.0.0 122 5/17/2024