How to update the page content in confluence?

atlassianaccount January 3, 2023

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))

1 answer

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 4, 2023

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

atlassianaccount January 4, 2023

I have already gone through the site but couldn't find an solution for the above script.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events