Does anyone have a powershell script which creates a confluence page and populates it with content? And perhaps a way to overwrite/replace a page if it already exists?
Community moderators have prevented the ability to post new answers.
I know this post is old, but since it is the first result of Google here is how I do it:
#Credentials
$creds = Get-Credential USERNAME
#ID of parant page. If you dont wont a parant just remove this and the ancestors part of the post request
$parantId = "14909521"
#The key to the Space
$key = 'TEST'
$title = 'A test page'
$pageContent = '
<h1>This is a test</h1>
<p>This site is created from Powershell</p>
'
#Generate post request as PowerShell objects
$post = @{
type = 'page'
"ancestors" = @(
@{"id" = $parantId}
)
title = $title
space = @{ key = $key}
body = @{
storage = @{
value = $pageContent
representation = 'storage'
}
}
}
#Convert post to json
$json = ConvertTo-Json $post
#Post request to Confluence
try {
Invoke-RestMethod -Uri 'http://confluenceurl.here/rest/api/content/' -Method POST -ContentType "application/json" -Body $json -Credential $creds
} catch {$_.Exception.Response }
Does anyone know if this script can handle attachments?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all,
If it helps, looks like someone has created a PowerShell module to wrap the REST API, PoshConfluence.
Have not tested this, but looks to have a reasonable number of functions / Cmdlets to work with.
Cheers!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Credentials $creds = Get-Credential USERNAME does not work.
use base Authentication as below
$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)) )))}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I know this post is old, but since it is the first result of Google here is how I do it:
#Credentials
$creds = Get-Credential USERNAME
#ID of parant page (If you dont wont a parant just remove this and the ancestors part of the post request)
$parantId = "14909521"
$key = 'TEST' # The key to the Space
$title = 'A test page'
$pageContent = '
<h1>This is a test</h1>
<p>This site is created from Powershell</p>
'
#Generate post request as PowerShell objects
$post = @{
type = 'page'
"ancestors" = @(
@{"id" = $parantId}
)
title = $title
space = @{ key = $key}
body = @{
storage = @{
value = $pageContent
representation = 'storage'
}
}
}
#Convert post to json
$json = ConvertTo-Json $post
#Post request to Confluence
try {
Invoke-RestMethod -Uri 'http://confluenceurl.here/rest/api/content/' -Method POST -ContentType "application/json" -Body $json -Credential $creds
} catch {$_.Exception.Response }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I recommend using the Confluence CLI Bob mentioned (which he maintains himself).
You can Script Confluence CLI, via Powershell as you want, or via PHP as in the following example:
$command = 'path\confluence-cli-3.3.0\confluence.bat --action addGroup --group "'.$groupName.'"'; exec($command, $output, $return_var);
Confluence CLI isn't using the REST API but another one that has the full set of calls implemented - the REST API hasn't all calls available as it's a prototype.
Does this help?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the response. I am, however, looking specifically at using the REST API.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Chris, did you ever get this resolved? I'm looking to do the same. Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Confluence Command Line Interface can be used, for instance: storePage
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, thanks for the reply. I had failed to mention that I'm looking to perform the update using the Confluence REST API. I have updated the title to reflect that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.