API access to confluence failing

Rahman April 24, 2023

I am trying to get confluence to integrate with Azure for documentation purposes. I get the error below.

`Invoke-RestMethod : HTTP Status 401 – Unauthorizedbody {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line
{height:1px;background-color:#525D76;border:none;}HTTP Status 401 – UnauthorizedType Status ReportMessage Basic Authentication Failure - Reason : com.atlassian.crowd.exception.FailedAuthenticationException: com.atlassian.crowd.exception.InvalidAuthenticationException:
Invalid credentialsDescription The request has not been applied because it lacks valid authentication credentials for the target resource.Apache Tomcat/9.0.71`

It suggests a permission issue i.e the 401 error code. Here is what I have done.

$SpaceKey = my-space"
$Page = ""
$Content = "<h1>This is a test</h1>"

$baseUri = 'https://xxxxxx.atlassian.net/wiki/'
$apikey = (az keyvault secret show --name 'apikey' --vault-name 'my-kv' | ConvertFrom-Json).value
$user = (az keyvault secret show --name 'username' --vault-name 'my-kv' | ConvertFrom-Json).value

write-output $apikey
write-output $user

$credential = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($User + ":" + $apikey))


function Get-RestHeaders {
return @{ 'Authorization' = 'Basic ' + $credential }
}

$headers = Get-RestHeaders
write-output $headers

The code above returns the headers

`Name Value
Authorization Basic dG95aW53ZWJAeWFob28uY28udWs6QVRDVFQzeEZmR04wNxxxxxxxxx`

However this section of the code is what is proving problematic.


$title = 'Documentation'
$headers = Get-RestHeaders
$uri = $baseUri + "rest/api/content?title=$($title.Trim() -replace " ", "+")&spaceKey=$SpaceKey"
$response = Invoke-RestMethod -Uri $uri -Method 'GET' -Headers $headers

`$response = Invoke-RestMethod -Uri $uri -Method 'GET' -Headers $heade CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
No page found matching Azure Resources - expected URL: https://xxxx.atlassian.net/wiki/rest/api/content?title=Azure+Resources&spaceKey=my-key`

0 answers

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