Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Jun 11, 2018

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

@PaulHalliday

This comment has been minimized.

Copy link

commented Jun 11, 2018

Great news! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.