PowerShell script to export notes?

System Info: Joplin 1.4.18 (prod, win32)

Question: Does anyone know how to write a PowerShell script to export Joplin notes to a local folder?

Bonus Question: I've noticed whenever I use the GUI to export, it won't "overwrite" if I choose the same folder. Is there a flag to overwrite the older files?

1 Like

Export as Markdown?
When yes, you can use the API the get the note body with powershell.

Or do you mean JEX / HTML / ... Export?

1 Like

Thanks for the quick reply and sorry about my delay.

I'm looking for a command that exports all the files in MD format similar to what the "export all" in GUI does.

I would also like to set it up in a way that consecutive export commands would overwrite the previous files exported to the same location instead of Joplin adding a (1), (2), etc. to the end of the file names

1 Like

There are no command line arguments with which you can do something like this.

You can use the API to go throu alle notes and save the content as md file.
The API command is GET /notes

2 Likes

Quick and dirty

$endpoint = "http://localhost:41184"
$token = "xxxxxxxxxx"


Try
{
    $uri = ($endpoint + "/ping")
    if( (Invoke-WebRequest -Uri $uri).Content -ne "JoplinClipperServer")
    {
        Write-Host "No Joplin API endpoint" -ForegroundColor Red 
        exit
    }
}
Catch
{
    Write-Host "Message: [$($_.Exception.Message)"] -ForegroundColor Red 
    exit
}


Try
{
    $page = 1
    Do
    {
        $uri = ($endpoint + "/notes?token=" + $token + "&fields=id,title,body&page=" + $page)
        $notes = (Invoke-WebRequest -Uri $uri).Content
        $notes = $notes | ConvertFrom-Json
        for ($i=0; $i -lt $notes.items.Count; $i++) {
            $id = $notes.items[$i].id
            $body = $notes.items[$i].body
            $title = $notes.items[$i].title
            $body | Out-File -FilePath ($title + ".md")
        }
        $page = $page +1
    } While ( $notes.has_more -eq $True )
}
Catch
{
    Write-Host "Message: [$($_.Exception.Message)"] -ForegroundColor Red 
    exit
}
3 Likes

Thanks for the detailed reply.This is a bit over my head (I don't atcually understand powershell) but I'll take a look at it.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.