-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToggl_Automate.ps1
57 lines (30 loc) · 1.52 KB
/
Toggl_Automate.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#Automate Timesheets
#Manually Adjust your date range below. Will skip weekends but not holdays, keep that in mind.
#Grab your API key from toggl.com, will prompt on run.
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$APIKEY = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Toggl API Key", "APIKEY", "")
#Toggl API Config
$pair = $APIKEY+ ':api_token'
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
}
#Time Loop
$startdate = Get-Date -Date '2016-09-01'
$enddate = Get-Date -Date '2016-09-30'
$difference = New-TimeSpan -Start $startdate -End $enddate
#$difference.Days
$days = [Math]::Ceiling($difference.TotalDays)+1
$workingDays = 1..$days | ForEach-Object {
$startdate
$startdate = $startdate.AddDays(1)
} | Where-Object { $_.DayOfWeek -gt 0 -and $_.DayOfWeek -lt 6}
Foreach($WorkingDay in $workingDays)
{
$DateToCreate = $WorkingDay.tostring("yyyy-MM-dd")
$DateToCreate
#$postParams = '{"time_entry":{"description":"API Test","duration":28800,"start":"2015-$Month-$DayT09:00:00.000Z","created_with":"curl"}}'
$postParams = '{"time_entry":{"description":"Support Work","duration":28800,"start":"'+ $DateToCreate + 'T13:00:00.000Z","pid":9040069,"created_with":"PowerShell"}}'
Invoke-WebRequest -Uri 'https://www.toggl.com/api/v8/time_entries' -Headers $Headers -ContentType "application/json" -Method Post -Body $postParams
}