Create a Tempo Account Using the REST API

Overview

Create a Tempo account (a way to track time across multiple teams and projects) using the Tempo REST API. Utilising the Tempo REST Endpoint, this script uses basic authentication in the headers of the request to authenticate the user. The authenticated user must have permission to create a Tempo account. Read more about permissions in Tempo in this article.

Example

I want to automate the creation of Tempo accounts to save time manually creating them, and make issue progress easy to track. I can use this script to trigger a Tempo account creation each time an Epic is created. Allowing me to track the time spent on issue in that Epic.

Good to Know

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.HttpResponseDecorator
import groovyx.net.http.RESTClient
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 data = [
    name  : "Account",
    key   : "12345",
    lead  : [
        key     : "admin",
        username: "admin"
    ],
    status: "OPEN"
]

def client = new RESTClient(baseUrl)
client.setHeaders([
    Authorization      : "Basic " + credentials.bytes.encodeBase64().toString(),
    "X-Atlassian-Token": "no-check"
])

client.handler.success = {
    log.debug "Account successfully created"
}

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

client.post(
    path: new URIBuilder("$baseUrl/rest/tempo-accounts/1/account/"),
    contentType: ContentType.JSON,
    body: data
)
Discovered an issue? Report it here

Suggested for you

Appears in these Collections