Created
May 17, 2016 18:55
-
-
Save dansmith65/7a753ddb89c9db145d41b0c4b3c7fac0 to your computer and use it in GitHub Desktop.
Powershell script to download the latest backup from Todoist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get-TodoistBackup.ps1 | |
# Created By: Daniel Smith [email protected] | |
# | |
# Download the latest backup from Todoist | |
# | |
$token = "" | |
# get list of backups from Todoist | |
$response = Invoke-WebRequest -Uri https://todoist.com/API/v6/backups/get -Body "token=$token" -Method Post | |
$code = $response.StatusCode | |
If ( $code -ne "200" ) | |
{ | |
Write-Error "unexpected response status code: $code" | |
Exit | |
} | |
# extract first backup | |
$backups = ConvertFrom-Json $response.Content | |
$url = $backups[0].url | |
$date = Get-Date $backups[0].version -Format FileDateTime | |
If ( -not $url ) | |
{ | |
Write-Error "no backups seem to exist" | |
Exit | |
} | |
# specify output file path/name | |
$fileExtension = $url.split(".")[-1] | |
If ( $fileExtension.length -gt 5 -or $fileExtension.length -lt 2 ) | |
{ | |
Write-Host "using default file extension of zip" | |
$fileExtension = "zip" | |
} | |
$filePath = "$PSScriptRoot\data\$date.$fileExtension" | |
# create directory, if needed | |
$parentDir = Split-Path -Path $filePath -Parent | |
If ( (Test-Path $parentDir) -eq 0 ) | |
{ | |
Write-Host "creating directories: $parentDir" | |
New-Item -Path $parentDir -Type directory | |
} | |
# download file | |
Invoke-WebRequest -Uri $url -Method Get -OutFile $filePath |
I've added a version with logging and win10 notifications on failure here https://gist.github.com/arberg/5c905272dd3ba41d767e0907b46cd675
Great news! 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Paul Halliday @ Todoist has been so kind as to fix this script for v7 where the download now requires the token as well.
https://gist.github.com/PaulHalliday/39f6b92164ae9c8df0016509971b4f93