• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Free Consultation
1300 887 889

PowerbITs

Making Technology Work For You

  • About
  • Managed IT Services
    • IT Service Plan
    • Network Security
    • Backup
    • Office Relocation
    • Mobile Device Management
  • Cyber Security
  • Business Process Automation
  • Contact

Use Powershell to access the Toggl API

Posted on July 3, 2015

Toggl is a time tracking web site & service.  It provides simple one click time tracking and is supported on most OS platforms and devices.   More details here.

Powerbits decided it could make use of the Toggl API and so put together the following sample script on how to access the Toggl API using Powershell.


$user = "01234567890123abcdef012345678912" # <-- enter your token here
$pass = "api_token"
$pair = "$($user):$($pass)"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$headers = @{ Authorization = $basicAuthValue }
$contentType = "application/json"

#Authorisation
##############
Invoke-RestMethod -Uri https://www.toggl.com/api/v8/me -Headers $headers -ContentType $contentType

#Get Workspaces
###############
Invoke-RestMethod -Uri "https://www.toggl.com/api/v8/workspaces" -Headers $headers -ContentType $contentType

#Get Users
##########
Invoke-RestMethod -Uri "https://www.toggl.com/api/v8/workspaces/123456/users" -Headers $headers -ContentType $contentType  # <-- enter your workspace here

#Reports Request Parameters
###########################
# user_agent: string, required, the name of your application or your email address so we can get in touch in case you're doing something wrong.
# workspace_id: integer, required. The workspace whose data you want to access.
# since: string, ISO 8601 date (YYYY-MM-DD), by default until - 6 days.
# until: string, ISO 8601 date (YYYY-MM-DD), by default today
# billable: possible values: yes/no/both, default both
# client_ids: client ids separated by a comma, 0 if you want to filter out time entries without a client
# project_ids: project ids separated by a comma, 0 if you want to filter out time entries without a project
# user_ids: user ids separated by a comma
# tag_ids: tag ids separated by a comma, 0 if you want to filter out time entries without a tag
# task_ids: task ids separated by a comma, 0 if you want to filter out time entries without a task
# time_entry_ids: time entry ids separated by a comma
# description: string, time entry description
# without_description: true/false, filters out the time entries which do not have a description ('(no description)')
# order_field:
# - date/description/duration/user in detailed reports
# - title/duration/amount in summary reports
# - title/day1/day2/day3/day4/day5/day6/day7/week_total in weekly report
# order_desc: on/off, on for descending and off for ascending order
# distinct_rates: on/off, default off
# rounding: on/off, default off, rounds time according to workspace settings
# display_hours: decimal/minutes, display hours with minutes or as a decimal number, default minutes

#Detail Report
#Last 6 days
##############
$uriReport = "https://toggl.com/reports/api/v2/[email protected]&workspace_id=123456" # <-- enter your email & workspace here
$TogglResponse = Invoke-RestMethod -Uri $uriReport -Headers $headers -ContentType $contentType
$responseTotal = $TogglResponse.total_count
$pageNum = 1
$DetailReport = @()
while ($responseTotal -gt 0)
{ 
    $TogglResponse = Invoke-RestMethod -Uri $uriReport+"&page="+$pageNum -Headers $headers -ContentType $contentType
    $TogglResponseData = $TogglResponse.data
    $DetailReport += $TogglResponseData
    $responseTotal = $responseTotal - $TogglResponse.per_page 
    $pageNum++
}
$DetailReport

Download Powershell Script

Toggl API Documentation

Filed Under: Uncategorized

Primary Sidebar

Recent Posts

Airtight Cybersecurity: Achieving Comprehensive Cyber Defence With Threat Exposure Management (TEM)

IoT Device Security – How to Keep Your Business and Home Devices Secure

Workplace Evolution – 5 Ways Will Likely Transform Modern Offices (Insights from LinkedIn & Microsoft Report)

Critical Response: 8 Immediate Steps to Protect Your Data After a Breach Notification

Adopting AI – 7 Examples of How Artificial Intelligence is Evolving Small Businesses

Footer

Menu

  • About
  • IT Service Plan
  • Managed IT Services
  • Cyber Security
  • Backup
  • Office Relocation
  • Mobile Device Management
  • How It Works
  • Blog
  • Contact

Contact Us

1300 887 889
Suite 102, 7 Merriwa St,
Gordon NSW 2072

How to Keep Your Data Secure

  • Get the seven things you must do to keep your business data secure...

© 2019 PowerbITs | Website by Website Love