Hi Guys,
I am trying fetch comments data for issues using JIRA API's but not able to do so as I am not able to authenticate/login.
I am using below code, Plz assist if I am making any mistake :
Sub JIRA()
Dim oJiraAuth As MSXML2.ServerXMLHTTP60
Dim oJiraService As MSXML2.ServerXMLHTTP60
Dim JIRA_USER As String, JIRA_PWD As String
' User id is the id shown in profile JIRA link https://Jiradomain/jira/people/xyz
JIRA_USER = "xyz"
JIRA_PWD = "abc$" ' Generated the token and using token number as password
Set oJiraAuth = New MSXML2.ServerXMLHTTP60
With oJiraAuth
.Open "POST", "https://iradomain/rest/auth/1/session", False
.setRequestHeader "Content-Type", "application/json"
.setRequestHeader "Accept", "application/json"
.send " {""username"" : """ & JIRA_USER & """, ""password"" : """ & JIRA_PWD & """}"
sOutput = .responseText
sCookie = "JSESSIONID=" & Mid(sOutput, 42, 32) & "; Path=/Jira"
End With
Set oJiraService = New MSXML2.ServerXMLHTTP60
With oJiraService
.Open "GET", "https://Jiradomain/rest/api/2/issue/AB-1/comment", False
.setRequestHeader "Content-Type", "application/json"
.setRequestHeader "Accept", "application/json"
.setRequestHeader "Authorization", "Basic " & EncodeBase64(JIRA_USER & ":" & JIRA_PWD)
'.setRequestHeader "Set-Cookie", sCookie
.send
sOutput = .responseText
sStatus = .Status & " | " & .statusText
End With
'sOutput should contain all data in JSON format
'next, you must use a JSON parser to get the desired format
Set oJiraService = Nothing
Set oJiraAuth = Nothing
End Sub
Private Function EncodeBase64(srcTxt As String) As String
Dim arrData() As Byte
arrData = StrConv(srcTxt, vbFromUnicode)
Dim objXML As MSXML2.DOMDocument60
Dim objNode As MSXML2.IXMLDOMElement
Set objXML = New MSXML2.DOMDocument60
Set objNode = objXML.createElement("b64")
objNode.DataType = "bin.base64"
objNode.nodeTypedValue = arrData
EncodeBase64 = objNode.text
Set objNode = Nothing
Set objXML = Nothing
End Function