Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Unable to login on jira api using vba

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

1 answer

0 votes
Warren Community Leader Dec 23, 2019

Hi @deepak.sirsale 

I think your problem is that you're using your User Id, it should be the Jira e-mail that you use to login

Thanks @Warren  I have tried using my email id which I use to login JIRA and now getting error code as 403 and error description as "XSRF check failed", Any clue why this is happening please.

Warren Community Leader Dec 23, 2019

Hi @deepak.sirsale 

I would suggest that you try using Postman (either online or download the app) to prove that you can successfully authorise. If what you're trying to do in Postman works, then you know that your login details are good and you can recheck your code.

In the meantime I'll try your code in Excel with my login details and URL to see if I can spot anything

Warren Community Leader Dec 23, 2019

Hi @deepak.sirsale 

Your EncodeBase64 function has an issue, but I'm not sure what.

When I run through your code and check the value that is returned from EncodeBase64, it has a carriage return character in it which shouldn't be there. I go to the Immediate window and type

?EncodeBase64 

and the result is returned across 2 lines.

I copied that into a text editor, removed the line break, copied the result back into the EncodeBase64 variable and it then works.

You need to try and track down why you're getting that character

Warren Community Leader Dec 23, 2019

Hi @deepak.sirsale 

I just tried using a different function - see improved function which works for me

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you