Document toolboxDocument toolbox

To learn more about Tempo products, please visit our Help Center. For support, see our Support Portal.

Creating a worklog with work attributes using the REST API

The script will create a worklog using the REST API. You might also refer to our REST API documentation. Using the REST APIs is better way to interact with Tempo since you don´t need to bother about packages to import nor need to be worried about deprecations and additionally you will find them documented.

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-defined property where the user name and password are stored into def baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL) def credentials = "username:password" def data = [ attributes : [ _Account_ : [ value: "201403" ], _Mileage_: [ value: "12" ], _WorklogCategory_: [ value: "Bugfixing" ], _Team_: [ value: "6" ] ], billableSeconds: "7200", worker: "john", comment: "worked on some stuff", started: "2019-12-05T13:00:00.000", timeSpentSeconds: 7200, originTaskId: "11290", remainingEstimate: 36000 ] def client = new RESTClient(baseUrl) client.setHeaders([ Authorization : "Basic " + credentials.bytes.encodeBase64().toString(), "X-Atlassian-Token": "no-check" ]) client.handler.success = { log.debug "Worklog successfully created" } client.handler.failure = { HttpResponseDecorator response -> log.error response.entity.content.text } client.post( path: new URIBuilder("$baseUrl/rest/tempo-timesheets/4/worklogs/"), contentType: ContentType.JSON, body: data )