An open API service indexing awesome lists of open source software.

https://github.com/abjerner/skybrud.social.toggl

.NET API wrapper and implementation of the Toggl Track API.
https://github.com/abjerner/skybrud.social.toggl

api api-client api-wrapper csharp dotnet limbo package skybrud skybrud-integrations skybrud-social social toggl toggl-track toggl-track-api toogl-api

Last synced: 25 days ago
JSON representation

.NET API wrapper and implementation of the Toggl Track API.

Awesome Lists containing this project

README

          

# Skybrud.Social.Toggl

[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/abjerner/Skybrud.Social.Toggl/blob/v1/main/LICENSE.md)
[![NuGet](https://img.shields.io/nuget/vpre/Skybrud.Social.Toggl.svg)](https://www.nuget.org/packages/Skybrud.Social.Toggl)
[![NuGet](https://img.shields.io/nuget/dt/Skybrud.Social.Toggl.svg)](https://www.nuget.org/packages/Skybrud.Social.Toggl)
[![Skybrud.Social.Toggl at packages.limbo.works](https://img.shields.io/badge/limbo-packages-blue)](https://packages.limbo.works/skybrud.social.toggl/)

.NET API wrapper and implementation of the [**Toggl Track API**](https://developers.track.toggl.com/docs/).


License:
MIT License


Target Framework:

.NET 4.5, .NET 4.6, .NET 4.7, .NET Standard 2.0 and .NET8



## Installation

The package is only available via [**NuGet**](https://www.nuget.org/packages/Skybrud.Social.Toggl/1.0.0-beta011). To install the package, you can either use the .NET CLI:

```
dotnet add package Skybrud.Social.Toggl --version 1.0.0-beta011
```

or the NuGet Package Manager:

```
Install-Package Skybrud.Social.Toggl -Version 1.0.0-beta011
```



## Examples

### Initialize a new HTTP service

The `TogglHttpService` class is the entry point for communicating with the Toggl Track API:

```cshtml
@using Skybrud.Social.Toggl
@{

// Initialize from your API token
TogglHttpService toggl = TogglHttpService.CreateFromApiToken("Your API token");

}
```

### List all clients

```cshtml
@using Skybrud.Social.Toggl
@using Skybrud.Social.Toggl.Exceptions
@using Skybrud.Essentials.Json
@using Newtonsoft.Json.Linq
@using Skybrud.Social.Toggl.Responses.Track.Clients
@inherits UmbracoViewPage
@{

// Declare your workspace ID
int workspaceId = 1234;

// Initialize from your API token
TogglHttpService toggl = TogglHttpService.CreateFromApiToken("Your API token");

try {

// Make the request to the API
TogglClientListResponse response = toggl.Track.Clients.GetClients(workspaceId);




ID
Name



@foreach (TogglClient client in response.Body) {

@client.Id
@client.Name

}

} catch (TogglHttpException ex) {

@ex.Response.StatusCode @ex.Response.ResponseUri


@(JsonUtils.TryParseJsonToken(ex.Response.Body, out JToken token) ? token : ex.Response.Body)

}

}
```

### List all projects

Projects are fetched via the **Projects** endpoint, and you must specify the ID of the workspace to retrieve projects for:

```cshtml
@using Skybrud.Social.Toggl
@using Skybrud.Social.Toggl.Exceptions
@using Skybrud.Essentials.Json
@using Newtonsoft.Json.Linq
@using Skybrud.Social.Toggl.Models.Track.Projects
@using Skybrud.Social.Toggl.Options.Track.Projects
@using Skybrud.Social.Toggl.Responses.Track.Projects
@inherits UmbracoViewPage
@{

// Declare your workspace ID
int workspaceId = 1234;

// Initialize from your API token
TogglHttpService toggl = TogglHttpService.CreateFromApiToken("Your API token");

try {

// Make the request to the API
TogglProjectListResponse response = toggl.Track.Workspaces.GetProjects(workspaceId);




ID
Name
ClientID
HEX



@foreach (TogglProject project in response.Body) {

@project.Id
@project.Name
@project.ClientId
@project.HexColor

}

} catch (TogglHttpException ex) {

@ex.Response.StatusCode @ex.Response.ResponseUri


@(JsonUtils.TryParseJsonToken(ex.Response.Body, out JToken token) ? token : ex.Response.Body)

}

}
```