How to post to a test instance of micro.blog with powershell
Source the micro.blog token
$BlogToken = $(import-csv /stuff/GeneralParameters.csv | ? parameter -eq 'BlogToken').value
$headers = @{
"Authorization" = "Bearer $BlogToken"
}
Get details for the micro.blog
$response = Invoke-RestMethod -Uri "https://micro.blog/micropub?q=config" -Headers $headers
This is the bit to get the uid of the test blog - mine is a fairly simple variation on the name of the main blog…as below. The URLEncode returns ‘https%3a%2f%2fmattypenny-test.micro.blog%2f’
$response | select -ExpandProperty destination
$MpDestination = [System.Web.HttpUtility]::UrlEncode("https://mattypenny-test.micro.blog/")
build the Uri to upload to
$mediaEndpoint = $response."media-endpoint"
$Uri ="${mediaEndpoint}?mp-destination=$MpDestination"
Identify the file to upload
$form = @{
file = Get-Item '/home/matty/working/spotify/images/Bethany Eve - Emerald City.png'
}
Upload it
Invoke-RestMethod -Uri $Uri -Method Post -Headers $headers -Form $form
And….hey presto