-
-
Save PaulHalliday/39f6b92164ae9c8df0016509971b4f93 to your computer and use it in GitHub Desktop.
FIX: Powershell script to download the latest backup from Todoist
This file contains hidden or 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 = "" | |
$headers = @{ | |
Authorization = "Bearer $token" | |
} | |
# get list of backups from Todoist | |
$response = Invoke-WebRequest -Uri https://todoist.com/api/v7/backups/get -Headers $headers | |
$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 -Headers $headers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment