Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to navigate jira java api documentation

raghuvarmaofficial February 7, 2023

Iam new to atlassian stack

I've been trying to write custom scripts for some purposes using script runner, but iam stuck.

I've been trying to get code from adaptivist library and make some changes and make it work somehow even after not knowing or have good knowledge about the functions iam just uisng them and making it work somehow .

I have some coding background so iam feeling a little insecure to write code this way , so i was trying to explore through jira java api  , but it's overwhelming , iam not making any progress in it .
can any of you guys explain how you go about exploring jira java api or how you write code for script runner like how to figure out what package to import what function to use etc.

1 answer

0 votes
Jeroen Poismans
Community Champion
February 7, 2023

Hi and Welcome!

Are you familiar with pom-files, working with an IDE ...? If so, this might help.

What I recommend is installing the Atlassian SDK:
https://developer.atlassian.com/server/framework/atlassian-sdk/

Then from that framework you can generate an Atlassian plugin skeleton:
https://developer.atlassian.com/server/framework/atlassian-sdk/create-a-helloworld-plugin-project

This will generate a plugin project which you can open with an IDE for example IntelliJ. If you create .groovy files here you will get code completion for the Jira API! The version of the API will be the one mentioned in the POM-file and can be changed:

Screenshot 2023-02-07 at 12.17.56.png

Hope this helps!

Regards,

Jeroen

raghuvarmaofficial February 7, 2023

Hi thank you for your answer, but if iam not wrong , isn't this for like when you are trying extend jira functionalities and make a separate app.

What i was asking was on how to come up with scripts or how to understand the jira java api , the link i have mentioned below , how to navigate and understand it

https://docs.atlassian.com/software/jira/docs/api/9.6.0/

Now iam only able to modify the code like the one below

//Code

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def issueService = ComponentAccessor.issueService
def issueManager = ComponentAccessor.issueManager

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def issueKey = 'TEST-1'

def issue = issueManager.getIssueObject(issueKey)
assert issue: "Could not find issue with key $issueKey"

def inputParams = issueService.newIssueInputParameters().tap {
it.setSummary('Hello ScriptRunner!')
}

def validation = issueService.validateUpdate(user, issue.id, inputParams)

if (validation.isValid()) {
def issueResult = issueService.update(user, validation, EventDispatchOption.ISSUE_UPDATED, false)
if (issueResult.isValid()) {
"${issue.key} updated"
} else {
log.error(issueResult.errorCollection.errors)
'Failed updating the issue'
}
} else {
log.error(validation.errorCollection.errors)
'Validation failed.'
}

//Code

this code now works in console , but if i try to make it work in listener i will have to use different code , use different functions , the thing is iam not getting what functions or packages

This is where iam stuck.

Thank you for answering the questions but if you can provide any guidance on i can how about it , that would help me alot

Jeroen Poismans
Community Champion
February 8, 2023

Hi!

Indeed, the plugin skeleton that is generated is for extending Jira with an app, but ... If you just create groovy files within this skeleton you will be able to leverage the Code completion that comes with the Atlassian SDK, thus ... you can modify your script there in the IDE, inspecting the entire Jira API.

When your script is ready just place it inside the Jira UI where you want to use it. The generated app skeleton is just there to create an environment where you can make use of the API support while developing scripts.

Regards,

Jeroen

Ikra Ahmed
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 6, 2024

@raghuvarmaofficial  are you able to find the answer of your question?

Suggest an answer

Log in or Sign up to answer