Hi All,
I have used the code given in this answer for JIRA as a starting point but I do not manage to get through...
What I want to do is to add (and / or update) an attachment sitting on my client laptop to a confluence page in our server instance using VBA code in an Excel file.
Below the code up to the last point where I got and the response text that I get back.
Sub rdd_sendAttachementToConfluencePagebyID()
Dim httpRestAPIreq As New WinHttpRequest
Dim strRequestBodyStart, strRequestBodyEnd, strPassword, strUsername, strBoundary, strBaseURL, strFullURL, strPageID, strFilePath, strFileName, strFileData As String
strFilePath = "C:\folder1\fodler2\file.png"
strPageID = "7340078"
strBaseURL = "http://theserver:8090"
strFullURL = strBaseURL & "/rest/api/content/" & strPageID & "/child/attachment"
strBoundary = "---------------------------7e0139a150b4e"
strUsername = "id"
strPassword = "pwd"
strRequestBodyStart = "--" & strBoundary & vbCrLf & _
"Content-Disposition: form-data; name=""file_0"";value = """ & strFilePath & """;" & vbCrLf & _
"Content-Type: application/octet-stream" & vbCrLf & vbCrLf
strRequestBodyEnd = vbCrLf & vbCrLf & "--" & strBoundary & "--"
With httpRestAPIreq
.Open "POST", strFullURL, False
.setRequestHeader "X-Atlassian-Token", "no-check"
.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & strBoundary
.setRequestHeader "Authorization", "Basic " & rdd_encodeBase64(strUsername & ":" & strPassword)
.send StrConv(strRequestBodyStart, vbFromUnicode) & rdd_getFileAsBinary(strFilePath) & StrConv(strRequestBodyEnd, vbFromUnicode) 'Converts from string to bytes
Debug.Print .responseText
End With
End Sub
Function rdd_encodeBase64(strStrinToEncode As String) As String
Dim arrData() As Byte
Dim objXML As New MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement
arrData = StrConv(strStrinToEncode, vbFromUnicode)
Set objNode = objXML.createElement("b64")
objNode.DataType = "bin.base64"
objNode.nodeTypedValue = arrData
rdd_encodeBase64 = objNode.Text
Set objNode = Nothing
Set objXML = Nothing
End Function
Function rdd_getFileAsBinary(ByVal strPath As String) As Variant
Dim buffer() As Byte
Dim lngLogFileHdl As Long
lngLogFileHdl = FreeFile
Open strPath For Binary As #lngLogFileHdl
ReDim buffer(1 To LOF(lngLogFileHdl))
Get #lngLogFileHdl, , buffer
Close #lngLogFileHdl
rdd_getFileAsBinary = buffer
End Function
I get back:
{"statusCode":400,"data":{"authorized":false,"valid":true,"errors":[],"notSuccessful":true,"successful":false},"message":"At least one attachment file must be included."}Can someone help me pointing out what I am doing wrong?