Get the token

Go to the account page in micro.blog, scroll down to the bottom where there is ‘App tokens’ and click on the link which has the text ‘5 apps’ (or however many apps you’ve authorized)

Screenprint of the link

Pick an app name (I went wild with my imagination and called it Powershell), and click on ‘Generate Token’

Screenprint of the App name box

Reveal the token and Ctrl-C it.

Do the powershell bit

Convert the token into a securestring

$Token = 'whatever-the-token-is' |  ConvertTo-SecureString -AsPlainText -Force

Set up the $Body

$Body = @{
  content = 'Testing again. 1 , 2, 1, 2'
  h = 'entry'
  'post-status' = 'draft'
}

You need the quotes around ‘post-status’ because Powershell doesn’t like hyphens in variable names. I’m keeping this post as draft, because the content is even less interesting than my other posts

Then call invoke-restmethod as follows:

invoke-restmethod https://micro.blog/micropub -Method post  -Authentication Bearer -Token $Token -Body $Body

…and Bob’s your uncle

Screen-print of the post

There is, clearly, a lot more really basic stuff that I need to work out:

  • how to create a title

  • how to make the URL more meaningful (tbf, I don’t know how to do that through the browser as yet)

  • how to attach a photo

  • how to post to the testing blog rather than the default one

Then, I’d like to:

  • create a function to select a particular post, download it, edit in in vim or vscode, then post the new version