Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

I'm getting a 403 Error when connection to Confluence REST API - 2FA

Roumimper M. (Maurice)
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!
July 12, 2023

When i Connect to Confluemce using the REST API i get an 403 error.

The ConfluenceURL and the PostURL are correct and show results in the webbrowser.

Within our company we use 2FA. Therefore I generated an API Token in Confluence and used it in this script.

Buit still i got an 403 error.

What could be wrong?

 

This is a part of the script i use:

Dim strApiToken: strApiToken = "<My Token>"

Dim strConfluenceURL: strConfluenceURL = "https://<MyCompany>.atlassian.net"
Dim strSpaceKey: strSpaceKey = "<MySpaceKey"
Dim strPageTitle: strPageTitle = "<MyPageTitle>"

Dim strPostURL: strPostURL = strConfluenceURL & "/rest/api/content"
Dim objHTTP: Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")

Dim strJSON
strJSON = "{""type"": ""page"",""title"": """ & strPageTitle & """, ""space"": {""key"": """ & _
strSpaceKey & """}, ""body"": {""storage"": {""value"": """ & _
Replace(strContent, """", "\""") & """, ""repressentation"": ""storage""}}}"

objHTTP.open "POST", strPostURL, False
objHTTP.setRequestHeader "Content-Type", "application/json"
objHTTP.setRequestHeader "Authorization", "Bearer " & strApiToken
objHTTP.send strJSON

 

1 answer

0 votes
Fabio Racobaldo _Catworkx_
Community Champion
July 13, 2023

Hi @Roumimper M. (Maurice)  and welcome,

403 error means forbidden so, first of all, you need to check user's permission on the target space.

Hope this helps,

Fabio

Roumimper M. (Maurice)
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!
July 14, 2023

Hello Fabio,

 

I found the issue.

The Authentication method shoul be Basic in stead of Bearer.
The ApiToken must consist of Username & ":" & API Token generated in Confluence then encoded to base64

That worked

 

strEncodedApiToken = Base64Encode(<My User Name> & ":" & <My API token>)

Function GetRequest(strPOSTURL, strEncodedApiToken )
Dim objHTTP
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
With objHTTP
.open "GET", strPOSTURL, False
.setRequestHeader "Authorization", "Basic " & strEncodedApiToken
.setRequestHeader "Content-Type", "application/json"
.send
End With
GetRequest = objHTTP.status & " :" & objHTTP.responseText
Set objHTTP = Nothing
End Function

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events