How to update the page content in confluence?
I tried the below code but I am getting error at this line$UpdateConfluence = Invoke-WebRequest -Method PUT -Uri ($ConfluenceURL + $Call) -Body $Body -ContentType $ContentType. Could you please help me find the resolution?
$Credentials = Get-Credential
$MaxJsonLength = 67108864
$ConfluenceURL = "https://confluenceurl/wiki/rest/api/"
$ConfluencePageID = "xxxxx"
$Headers = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(($Credentials.UserName+":"+[System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($Credentials.Password)) )))}
$Call = "content/$($ConfluencePageID)?expand=body.storage,version,space,ancestors"
$CurrentConfluence = Invoke-WebRequest -Method GET -Headers $Headers -Uri ($ConfluenceURL + $Call)
$JSONSerial = New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer
$JSONSerial.MaxJsonLength = $MaxJsonLength
$CurrentConfluence = ($JSONSerial.DeserializeObject($CurrentConfluence))
$Body = @{
"id" = ($CurrentConfluence.id)
"type" = "page"
"title" = ($CurrentConfluence.title)
"version" = @{
"number" = ($CurrentConfluence.version.number + 1)
}
"status" = "current"
"space" = @{
"id" = ($CurrentConfluence.space.id)
"key" = ($CurrentConfluence.space.key)
"name" = ($CurrentConfluence.space.name)
"type" = ($CurrentConfluence.space.type)
}
"ancestors" = @{
"id" = ($CurrentConfluence.ancestors.id)
"type" = ($CurrentConfluence.ancestors.type)
"status" = ($CurrentConfluence.ancestors.status)
"title" = ($CurrentConfluence.ancestors.title)
}
"body" = @{
"storage" = @{
"value" = "This is a newly-posted Confluence page"
"representation" = "editor"
}
}
}
$Body = $Body | ConvertTo-Json
$ContentType = "application/json"
$Call = "content/$($ConfluencePageID)"
$UpdateConfluence = Invoke-WebRequest -Method PUT -Uri ($ConfluenceURL + $Call) -Body $Body -ContentType $ContentType
$JSONSerial = New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer
$JSONSerial.MaxJsonLength = $MaxJsonLength
$UpdateConfluence = ($JSONSerial.DeserializeObject($UpdateConfluence))
Hi @atlassianaccount ,
welcome to the Atlassian community!
Please take a look to some examples provided in the rest Api section https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-content/#api-wiki-rest-api-content-id-put
Hope this helps,
Fabio
I have already gone through the site but couldn't find an solution for the above script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.