Connecting to Confluence with API key and ConfluencePS

Brendan February 17, 2023

I am trying to connect to my company's confluence space by using the ConfluencePS but I cannot seem to authenticate my account.

I have created an PAT on both Atlassian.net and directly on the Data Center that Confluence is hosted on. Neither seem to work.

The URI is set up in the format "https://confl.CompanyName.com".

The code I am using to attempt to connect is shown below.


Import-Module ConfluencePS
$Username = 'first.last@mycompany.com'
$Password = 'full_token_string' | ConvertTo-SecureString -AsPlainText -Force

$Credentials = New-Object System.Management.Automation.PsCredential($Username,$Password)

Set-ConfluenceInfo -BaseURI 'https://confl.CompanyName.com' -Credential $Credentials

Get-ConfluenceSpace  -SpaceKey '####'


When this runs, I receive back a 401: UNAUTHORIZED error

I've also tried for the password, the token name, the Atlassian token, the password to my account, the token on the data center. I can't seem to find what is expecting.

 

Can ConfluencePS work on Data Center based Confluence pages? How can I go about using this?

 

2 answers

1 vote
Andrii Maliuta
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 19, 2023

@Brendan ,

You can try first if Authentication works using other method like CURL or HTTPIE or Postman, etc. just to be sure that the user/password and the encoded password work. For authentication you can use headers as { "Authentication": "Basic {base64encodedPassword}"}.

 

Powershell simple GET to check auth:

$cred = Get-Credential
Invoke-WebRequest -Uri 'https://confl.CompanyName.com/rest/api/content' -Credential $cred
Invoke-WebRequest -Method Get -Uri 'https://confl.CompanyName.com/rest/api/content' -Authentication Basic 

 

other clis:

https -a user:pass https://confl.CompanyName.com/rest/api/content

curl -X user:pass https://confl.CompanyName.com/rest/api/content

https -a user:pass https://confl.CompanyName.com/rest/api/content
Brendan February 21, 2023

Thanks for the answer, it seems like I am able to reach the API when using the Invoke-WebRequest or curl methods but when I try to do anything with the ConfluencePS module, I still am seeing the 401 error. Image attached for reference.

ConfluencePS_no_work.png

Andrii Maliuta
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 22, 2023

@Brendan ,

It needs more deep debugging of what is the cause in code. Maybe it would be better to contact the team of ConfuencePS:

https://atlassianps.org/module/ConfluencePS/

https://atlassianps.org/slack

Brendan February 23, 2023

Thanks for all the help. I have posted within there. If I find an answer I will be sure to post it here.

Like Andrii Maliuta likes this
Tom Cappellino April 26, 2023

Any luck?

0 votes
tristian o_brien
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 11, 2024

 like this?

Import-Module ConfluencePS

$Username = '************@gmail.com'

#generate a key from here https://id.atlassian.com/manage-profile/security/api-tokens

$Key = '******************************************' `

    | ConvertTo-SecureString -AsPlainText -Force

$Credentials = New-Object System.Management.Automation.PsCredential($Username,$Key)

#Set-ConfluenceInfo -BaseURI 'https://********.atlassian.net/wiki' -Credential $Credentials

Get-ConfluenceSpace

#https://***********.atlassian.net/wiki/spaces/~712020e628e2b3818645efb1b64e5371f102bc/pages/294914/page+1

 

Get-ConfluencePage -PageID 294914 | Format-List * #get page info including content

#get space ley from it's url

$pages = Get-ConfluencePage -SpaceKey "~712020e628e2b3818645efb1b64e5371f102bc"

$pages | ForEach-Object { $_.Body } #gets page content as HTML

 

Gist https://gist.github.com/tristian2/c33692cbe46e287dd4f9bd5bb887ddb5




Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events