We use a bunch of boards as templates and my colluagues have gone wild with links within a board.
When I duplicate a board or when I import it as a backup, all of those links still point to the original board.
I tried editing the backup file and making the link `?movetoWidget=283917482397498324`, whicn in theory should work, but the app prepends `http://` and claims the link is invalid.
I tried the API, but many oobjects that can contain links can't be updated. Even ones that are documented, like `shape`.
My code:
$goodboardId = "o9J_xxxxx"
$badBoardId = "o9J_yyyyy"
$goodBoard = "https://miro.com/app/board/o9J_xxxxx#61;"
$badboard = "https://miro.com/app/board/o9J_yyyyyyy="
$boardUri = "https://api.miro.com/v1/boards/$goodboardId"
$headers = @{ Authorization = 'Bearer XXXXXXX'}
$supportedTypes = @("Sticker", "Shape", "Text", "Line", "Card")
$widgets = Invoke-RestMethod -Uri "$boardUri/widgets/" -Method GET -Headers $headers
$widgets.data | ?{ $_.text } | %{
$originalText = $_.text
$newText = $originalText -replace $badboard,$goodBoard
if ($originalText -ne $newText)
{
if ($supportedTypes -contains $_.type)
{
$widget = $_ # Invoke-RestMethod -Uri "$boardUri/widgets/$($_.id)" -Method GET -Headers $headers
$widget.text = $newText
$patch = @{
id = $widget.id
text = $newText
type = $widget.type
}
$body = $patch | ConvertTo-Json -Depth 100
try {
Invoke-RestMethod -Uri "$boardUri/widgets/$($_.id)" -Method PATCH -Headers $headers -Body $body
}
catch {
Write-Error ($patch | ConvertTo-Json -Depth 100)
throw
}
}
else
{
Write-Error "Could not update widget:"
Write-Debug $_
}
}
}
Results in:
{
"text": "<p><a href=\"https://miro.com/app/board/o9J_xxxxxc&61;/?moveToWidget=3074457352041839530&cot=10\" style=\"color:rgb(255,255,255)\">INTRODUCE</a></p><p><a href=\"https://miro.com/app/board/o9J_xxxxxx#61;/?moveToWidget=3074457352041839530&cot=10\" style=\"color:rgb(255,255,255)\">YOURSELF</a></p>",
"id": "3074457352436545188",
"type": "shape"
}
Invoke-RestMethod: C:\Users\jesse\Desktop\Fix-Board-Links.ps1:33:17
Line |
33 | … Invoke-RestMethod -Uri "$boardUri/widgets/$($_.id)" -Meth …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| { "status" : 415, "code" : "mediaTypeNotSupported", "message" : "Specified media type not supported for this endpoint", "context" : null, "type" : "error" }
Plus, it seems the API can't patch "locked" objects, nor do I have a unlock/lock option in the patch command as fas as I can tell.
not breaking in-board-links seems a pretty normal thing to ask...