Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,577
Community Members
 
Community Events
176
Community Groups

How to update the page content in confluence?

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

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.

Suggest an answer

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

Atlassian Community Events