PDA

View Full Version : Posting Issues to Jira using VBA



samuelimtech
07-02-2021, 05:29 AM
Hi all,

as the title suggests im looking to try and automate creating jira's but running into problems when trying to post.

The authorization code seems to work as there's no failure when i use GET.

the JSON seems to be ok.

The error i recieve is "XSRF check failed" which upon research suggests im missing an additional authorisation step when posting data but i can't work out what's missing.




Private JiraService As New MSXML2.XMLHTTP30
Private arrData() As Byte


Sub Test()


Dim objRequest As Object
Dim blnAsync As Boolean
Dim strResponse As String
Dim UserName, Password As String
Dim sURL, strURL As String

UserName = "XXXX"
Password = "XXXXX"
Call isAuthorized


Set objRequest = CreateObject("MSXML2.XMLHTTP")



sURL = "https://jira.XXX.com"

m_sJSONString = json_Formatter()


With objRequest
.Open "POST", sURL & "/rest/api/2/issue/", False
.setRequestHeader "Content-Type", "application/json"
.setRequestHeader "Accept", "application/json"
.setRequestHeader "Authorization", "Basic " & EncodeBase64
.send m_sJSONString
If .Status <> 401 Then
m_sJSONString = .responseText
Else
m_sJSONString = "Error: Invalid Credentials!"
End If

End With




Debug.Print m_sJSONString


End Sub

SamT
07-02-2021, 07:14 AM
The only VBA errors(?) I see is that "Dim sURL, " makes sURL a Variant, which doesn't matter in VBA, and the 2 module level Variables are not used.

Also, https://jira.XXX.com is not a valid Internet address.

Place "Option Explicit" at the top of the Code Page. Debug >> Compile the code and fix any errors. Then Use F8 to step thru the code and fix any errors found that way.







Finally, if you can't get jira working, take a look at FogBugz. Disclaimer, I am not a user of fogbugz, nor associated with them. I just admire Joel Spotsky.

snb
07-02-2021, 07:30 AM
.setRequestHeader "Authorization", "Basic " & EncodeBase64


The variable EncodeBase64 has no content, nor is it declared.

@SamT

Previously you seemed a fan of Spolsky ?
You changed your bets ?

SamT
07-02-2021, 10:15 AM
Sploky's outfit invented foxbugz