Kaonavi.NET
2.0.0-beta.2
This is a prerelease version of Kaonavi.NET.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Kaonavi.NET --version 2.0.0-beta.2
NuGet\Install-Package Kaonavi.NET -Version 2.0.0-beta.2
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="Kaonavi.NET" Version="2.0.0-beta.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kaonavi.NET" Version="2.0.0-beta.2" />
<PackageReference Include="Kaonavi.NET" />
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 Kaonavi.NET --version 2.0.0-beta.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Kaonavi.NET, 2.0.0-beta.2"
#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 Kaonavi.NET@2.0.0-beta.2
#: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=Kaonavi.NET&version=2.0.0-beta.2&prerelease
#tool nuget:?package=Kaonavi.NET&version=2.0.0-beta.2&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Kaonavi.NET
Unofficial Kaonavi Library for .NET
Install
# Package Manager
> Install-Package Kaonavi.NET
# .NET CLI
> dotnet add package Kaonavi.NET
Usage
事前に公式APIドキュメントの手順に従い、Consumer KeyとConsumer Secretを取得してください。
Basic
using Kaonavi.Net;
using Kaonavi.Net.Entities;
var client = new KaonaviClient(new HttpClient(), "Your Consumer Key", "Your Consumer Secret");
// アクセストークンは最初にAPIを呼び出す際に自動で取得されます
// 所属ツリー 一括取得APIを呼び出す
// https://developer.kaonavi.jp/api/v2.0/index.html#tag/%E6%89%80%E5%B1%9E%E3%83%84%E3%83%AA%E3%83%BC/paths/~1departments/get
var departments = await client.Department.ListAsync();
// メンバー情報 登録APIを呼び出す(戻り値はタスクID)
// https://developer.kaonavi.jp/api/v2.0/index.html#tag/%E3%83%A1%E3%83%B3%E3%83%90%E3%83%BC%E6%83%85%E5%A0%B1/paths/~1members/post
int taskId = await client.Member.CreateAsync(new MemberData[]
{
new MemberData(
Code: "A0002",
Name: "カオナビ 太郎",
NameKana: "カオナビ タロウ",
Mail: "taro@kaonavi.jp",
EnteredDate: new DateOnly(2005, 9, 20),
RetiredDate: null,
Gender: "男性",
Birthday: new DateOnly(1984, 5, 15),
Department: new MemberDepartment("1000"),
SubDepartments: new MemberDepartment[] { new MemberDepartment("1001") },
CustomFields: new CustomFieldValue[] { new CustomFieldValue(100, "A") }
),
});
// 上記APIがサーバー側で処理されるまで待つ
await Task.Delay(10000);
// タスク進捗状況 取得APIを呼び出す
// https://developer.kaonavi.jp/api/v2.0/index.html#tag/%E3%82%BF%E3%82%B9%E3%82%AF%E9%80%B2%E6%8D%97%E7%8A%B6%E6%B3%81/paths/~1tasks~1%7Btask_id%7D/get
var progress = await client.Task.ReadAsync(taskId);
if (progress.Status == "NG" || progress.Status == "ERROR")
{
// エラー処理
}
.NET Generic Host
.NET Generic Hostを用いて、HttpClientのインスタンスを外部から注入することができます。
コンソール アプリの完全なサンプルはConsoleAppSampleを参照してください。
WIP
Source Generator
Kaonavi.NETでは、独自のクラスからシート情報への生成を簡単にするためのソース ジェネレーターを提供しています。
Visual Studio 2022 (バージョン 17.3)以降、もしくは Visual Studio Code の C# 拡張機能などのMicrosoft.CodeAnalysis.CSharp 4.3.0以降に対応したエディターが必要です。
using Kaonavi.Net;
using Kaonavi.Net.Entities;
// 1. SheetSerializable属性を付与したpartialクラス(recordクラスも可)を定義
[SheetSerializable]
public partial class Position : ISheetData // 2. ISheetDataを実装
{
public string Code { get; set; } // 3. ISheetData.Codeプロパティを実装
[CustomField(100)] // 4. カスタムフィールドとなるプロパティにCustomField属性を付与
public string Name { get; set; }
// 以下のメソッドが自動生成される
public IReadOnlyList<CustomFieldValue> ToCustomFields() => new CustomFieldValue[]
{
new CustomFieldValue(100, Name),
};
}
var positions = new Position[]
{
new Position { Code = "A0001", Name = "社長" },
new Position { Code = "A0002", Name = "部長" },
};
var client = new KaonaviClient(new HttpClient(), "Your Consumer Key", "Your Consumer Secret");
// ISheetDataを実装することで、シート情報に変換する拡張メソッドが利用可能
// IEnumerable<ISheetData>.ToSingleSheetData(): 単一レコードのシート情報に変換
// IEnumerable<ISheetData>.ToMultipleSheetData(): 複数レコードのシート情報に変換
var sheetDataList = positions.ToSingleSheetData();
// シート情報 一括更新APIを呼び出す
// https://developer.kaonavi.jp/api/v2.0/index.html#tag/%E3%82%B7%E3%83%BC%E3%83%88%E6%83%85%E5%A0%B1/paths/~1sheets~1%7Bsheet_id%7D/put
var taskId = await client.Sheet.ReplaceAsync(i, sheetDataList);
Development & Contributing
CONTRIBUTING.mdを参照してください。
There are no supported framework assets in this package.
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Kaonavi.NET.Core (>= 2.0.0-beta.2)
- Kaonavi.NET.Generator (>= 2.0.0-beta.2)
-
net8.0
- Kaonavi.NET.Core (>= 2.0.0-beta.2)
- Kaonavi.NET.Generator (>= 2.0.0-beta.2)
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 |
|---|---|---|
| 4.0.0 | 117 | 5/12/2026 |
| 3.1.0 | 389 | 9/26/2025 |
| 3.0.0 | 547 | 5/1/2025 |
| 2.0.0 | 538 | 4/27/2024 |
| 2.0.0-beta.2 | 390 | 4/27/2024 |
| 2.0.0-beta.1 | 346 | 4/23/2024 |
| 1.2.0 | 249 | 3/20/2024 |
| 1.1.0 | 291 | 6/9/2023 |
| 1.0.1 | 487 | 2/9/2023 |
| 1.0.0 | 577 | 10/7/2022 |
| 0.3.0 | 618 | 5/26/2022 |
| 0.2.0 | 660 | 11/5/2021 |
| 0.1.0 | 489 | 6/10/2021 |