Example scripts
To homepage
Jira

Get Tempo Plans Using the REST API for a Set Time Period
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira (7.7 - 8.6)

ScriptRunner For Jira (5.6.14)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import groovyx.net.http.ContentType
import groovyx.net.http.EncoderRegistry
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient
import java.time.LocalDate
import java.time.format.DateTimeFormatter
// The user-defined property where the user name and password are stored into
final userPropertyKey = "jira.meta.basicAuthCreds"
// ID of the item which the plan is for
final planItemId = 1
// By default, startDate and endDate is set to today date
final today = DateTimeFormatter.ISO_LOCAL_DATE.format(LocalDate.now())
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def credentials = ComponentAccessor.userPropertyManager.getPropertySet(loggedInUser).getString(userPropertyKey)
def baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)
def client = new RESTClient(baseUrl)
client.encoderRegistry = new EncoderRegistry(charset: 'UTF-8')
client.setHeaders([
Authorization : "Basic ${credentials.bytes.encodeBase64()}",
"X-Atlassian-Token": "no-check"
])
client.handler.success = { resp, reader ->
def plannedTime = (reader as List<Map>).'seconds'.sum() ?: 0
log.debug "Total planned time: $plannedTime"
plannedTime
}
client.handler.failure = { HttpResponseDecorator response ->
log.error response.entity.content.text
}
client.get(
path: '/rest/tempo-planning/1/allocation',
contentType: ContentType.JSON,
query: [
planItemId : planItemId,
planItemType: 'ISSUE',
assigneeType: 'user',
startDate : today,
endDate : today
]
)
Having an issue with this script?
Report it here