Skip to content

Instantly share code, notes, and snippets.

@dansmith65
Created May 17, 2016 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dansmith65/7a753ddb89c9db145d41b0c4b3c7fac0 to your computer and use it in GitHub Desktop.
Save dansmith65/7a753ddb89c9db145d41b0c4b3c7fac0 to your computer and use it in GitHub Desktop.
Powershell script to download the latest backup from Todoist
# Get-TodoistBackup.ps1
# Created By: Daniel Smith dan@dansmith65.com
#
# 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
@arberg
Copy link

arberg commented Jun 11, 2018

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

@arberg
Copy link

arberg commented Jun 11, 2018

I've added a version with logging and win10 notifications on failure here https://gist.github.com/arberg/5c905272dd3ba41d767e0907b46cd675

@PaulHalliday
Copy link

Great news! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment