Forums

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

Tempo API search plan items by team

Contact IT July 19, 2022

Hello,


Recently I've been implementing some automation that require some Tempo data, and to achieve my goals I'd need to retrieve all the planned items for a specific Tempo Team.
For now I've not been successful as it seems that the queries I've tried all return empty results.
I've tried multiple options based on the tempo planner allocation endpoint:
https://www.tempo.io/server-api-documentation/planner?hsLang=en#tag/Allocation
I've tried this call with the assigneeType as "team", but doesn't matter what I fill on the assigneeKeys field I always get an empty response,
As I understand it, this should have the team ID from the team I'm trying to retrieve data from, I've tried both the ID numeric value as well as the team name but I haven't got any response.


Is what I'm trying to do even possible? If it is I'd like to know what I'm getting wrong here.

1 answer

1 vote
Tom Lister
Community Champion
July 27, 2022

Hi @Contact IT 

I have done this by using the Tempo Team custom field on a ticket. The data is extracted in a workflow post function and attached to the ticket.

These are my functions for getting team info. They are located in a class saved in the Script Editor scriptrunner data.

called as

int teamParam = ExtractWorklogUtils.getTeamId
((String)team, baseUrl, TempoConstants.CREDENTIALS)

 

static int getTeamId(String teamName, String baseUrl, String  credentials)  {

        RESTClient restClient

        HttpResponseDecorator response

        int retval = 0

        try {

            restClient = new RESTClient(baseUrl)

            restClient.encoderRegistry = new EncoderRegistry(charset: 'UTF-8')

            restClient.setHeaders([

                Authorization      : "Basic ${credentials.bytes.encodeBase64()}",

                "X-Atlassian-Token": "no-check",

                Accept: "*/*" ,

                "Content-Type": "application/json"

            ])

            response = restClient.get(path: '/rest/tempo-teams/2/team', contentType: ContentType.JSON )

            if (response) {

                switch (response.status) {

                    case 200:

                        response.data.each() {

                        if (it.name.equals(teamName)) {

                            retval = it.id

                        }

                    }       

                    default:

                        logit.info "Whats this   ${response.status}"

                    }

            }

        } catch (Exception e) {

            logit.info e.getMessage()

        }

     

        return retval

    }

     

    static ArrayList getTeamMembers(int teamId, String baseUrl) {

        RESTClient restClient

        HttpResponseDecorator response

        ArrayList retval = new ArrayList()

         

        try {

            restClient = new RESTClient(baseUrl)

            restClient.encoderRegistry = new EncoderRegistry(charset: 'UTF-8')

            restClient.setHeaders([

                Authorization      : "Basic ${TempoConstants.CREDENTIALS.bytes.encodeBase64()}",

                "X-Atlassian-Token": "no-check",

                Accept: "*/*" ,

                "Content-Type": "application/json"

            ])

            response = restClient.get(path: '/rest/tempo-teams/2/team/'+teamId+'/member', contentType: ContentType.JSON )

     

        } catch (Exception e) {

            logit.info "Error      : ${e.getMessage()}"

            logit.info "Message    : ${e.response.data}"

            logit.info "Reason.    : ${e.response.getStatusLine().getReasonPhrase()}"

            logit.info e.getMessage()

        }

 

        if (response) {

            switch (response.status) {

             case 200:

                logit.info "Process :-"

            def jdata = groovy.json.JsonOutput.toJson(response.data)

                def json = new JsonSlurper().parseText(jdata)

                json.each() {

                    retval.add(it.member.name)

                 }

 

            }

        

    

        return retval

        }

 

 

    }

  

Tom Lister
Community Champion
July 27, 2022

The teamid is added to a json body

StringBuffer jsonBody = new StringBuffer()

jsonBody.append("{")

jsonBody.append('"from":"' + startParam + '"')

if (end) {

    jsonBody.append(', "to":"' + endParam + '"')

}

if (team) {

    jsonBody.append(',"teamId":[' + teamParam + ']')

}

jsonBody.append("}")

This search call is like this

 

RESTClient restClient

HttpResponseDecorator response

try {

    restClient = new RESTClient(baseUrl)

    restClient.encoderRegistry = new EncoderRegistry(charset: 'UTF-8')

    restClient.setHeaders([

        Authorization      : "Basic ${TempoConstants.CREDENTIALS.bytes.encodeBase64()}",

        "X-Atlassian-Token": "no-check",

        Accept: "*/*" ,

        "Content-Type": "application/json"

    ])

     

    response = restClient.post(path: '/rest/tempo-timesheets/4/worklogs/search', contentType: ContentType.JSON, body: "${jsonBody.toString()}" )

    logit.info response

    logit.info "Status     : ${response.status}"

    logit.info "Body       : ${response.data.text}"

} catch (Exception e) {

    logit.info "Error      : ${e.getMessage()}"

    logit.info "Message    : ${e.response.data}"

    logit.info "Reason.    : ${e.response.getStatusLine().getReasonPhrase()}"

    logit.info e.getMessage()

    commentBody.append "|Response Error     | ${e.statusCode}|\n"

    commentBody.append "|Message            | ${e.response.data}|\n"

    commentBody.append "|Reason         | ${e.response.getStatusLine()}|\n"

}
Like Dave Rosenlund _Trundl_ likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events