Looking for a jump start / example code on how to ...
# lucee
r
Looking for a jump start / example code on how to create a new task (bug) in Jira using their API via Lucee / CFML. I am able to authenticate and get a list of projects. the /rest/2/api/issue/createmeta/(projectid)/issuetypes doesn't work for me, and I'm not sure what parameter(s) to load up (presumably with JSON) and send via cfhttpparam (e.g. is it type="body" name="fields" ??) Just need a little kicker to get me rolling. Appreciate any help on this!
z
this might help https://github.com/lucee/lucee-data-provider/blob/master/update/Jira.cfc ? we only use it to read issues so it may be bit rotted
👀 1
r
Thank you, @zackster! That's a pretty deep dive with a number of clues!
z
how did you go?
r
Hey, thanks for asking! While searching everywhere for the answers, I found that @alholden had pinged someone about a Jira question back in 2019, so I reached out to him on a DM and he graciously gave me a solid chunk of time where we bounced ideas around a bit. He didn't have direct knowledge of this, but he has worked with REST API's and clued me in where I was floundering. I now have a pretty solid grasp of using Jira's REST API with Lucee. So far I have pulled a list of projects, pulled single tickets, searched for tickets, added sub-tasks, and now I'm trying to update a custom field that we're going to use as a counter. My goal for this is to auto-create Jira Bug tickets from Errors, but I don't want to create bug tickets for the same error over and over, so we decided we'll likely log some of the pertinent info in a table and we'll just increment a counter if we find we've already created a bug ticket for that particular error. Miles to go, yet, but I've come a long way since yesterday!
For example, without compromising our security too much, this will search jira tickets for specific things using a basic authentication key. <cfset tSearchLabels = 'BugTracker' /> <cfset tSearchPhrase = 'Is Testing' /> <cfset tSearchDateMin = '2023/07/31' /> <!--- customfield_11452 is the Bug Detail counter field. ---> <cfset obodyValue = '{ "jql":"project=#tProjectKey# AND created > \"#tSearchDateMin#\" AND issuetype=#tIssueType# AND labels=#tSearchLabels# AND summary ~ \"#tSearchPhrase#\" AND resolution=Unresolved", "fields":["summary","customfield_11452"], "startAt": 0, "maxResults": 1 }' /> <cfhttp url="https://cfcorg.atlassian.net/rest/api/2/search" method="POST"> <cfhttpparam type="header" name="Authorization" value="Basic #t64encode#"> <cfhttpparam type="header" name="Content-Type" value="application/json"> <cfhttpparam type="body" value="#obodyValue#"> </cfhttp> <cfset tJSON=DeserializeJSON(cfhttp.filecontent)>
z
Cool, have you tried sentry?
r
What is Sentry?
P.S. for anyone searching for this or a similar solution, this link was most helpful for me, once I paid attention to the doc details. https://docs.atlassian.com/software/jira/docs/api/REST/9.10.0/#api/2/
z
Sentry is an error logging system, you can link it to JIRA to create issues after review. Usually there's so much noise, you only want to manually raise issues
r
Nice, I'll have to check it out