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

Overview

Gather all existing Tempo plans for a Jira issue (defined by its ID from Jira, and interpreted as the planItemId in Tempo) for a given period (start date to end date) using the Tempo REST API. This script uses the Tempo REST Endpoint with a basic authentication in the headers of the request. The authenticated user must have permission to view the plans for users; otherwise, the API does not return plans. Read more about permissions in Tempo in this article.

Example

As a project manager, I want to see the total time planned for projects in my next sprint. I need to know if the planned work is greater than my team capacity. I can use this script to see the total planned time for selected projects over the two week sprint period.

Good to Know

  • This script requires Tempo Planner by Tempo for Jira.

Requirements

Jira Jira (7.3 - 7.13)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.URIBuilder

// the user property where the user name and password are stored into
final String userPropertyKey = "jira.basic.auth.creds"

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.setHeaders([
    Authorization      : "Basic " + credentials.bytes.encodeBase64().toString(),
    "X-Atlassian-Token": "no-check"
])

client.handler.success = { resp, reader ->
    def plannedTime = (reader as List).'seconds'.sum() ?: 0
    log.debug "Total planned time: $plannedTime"
}

client.handler.failure = { HttpResponseDecorator response ->
    log.error response.entity.content.text
}

client.get(
    path: new URIBuilder("$baseUrl/rest/tempo-planning/1/allocation"),
    contentType: ContentType.JSON,
    query: [
        planItemId  : 12094,
        planItemType: 'ISSUE',
        assigneeType: 'user',
        startDate   : '2019-01-01',
        endDate     : '2020-01-01'
    ]
)
Discovered an issue? Report it here

Suggested for you

Appears in these Collections