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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.