Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to add a user to a Tempo Team using API Edited

Hi, I'm new to using REST APIs, and I'm trying to figure out how to use ScriptRunner to automatically add a user to a specific Tempo Team.

I've been looking at the documentation here: https://www.tempo.io/server-api-documentation/teams#operation/addMember

but I haven't been able to get it to work, every time I try, I get a 500 response code and no response message. Has anyone hear been able to add a user to Tempo Teams via REST APIs, especially from ScriptRunner?

My code is below:

import com.atlassian.jira.component.ComponentAccessor
import java.nio.charset.StandardCharsets;
import groovy.json.StreamingJsonBuilder
import groovy.json.JsonSlurper

def jsonSlurper = new JsonSlurper()
def request = jsonSlurper.parseText("\"member\":{\"type\":\"USER\",\"key\":\"<userkey>\"},\"membership\":{\"role\":{\"id\":1},\"dateFrom\":\"2019-05-28\",\"dateTo\":\"2019-06-28\",\"availability\":\"100\"}")
def username = "username"
def password = "password"
def url = new URL("https://<baseURL>/rest/tempo-teams/2/team/67/member")
String encoded = Base64.getEncoder().encodeToString((username+":"+password).getBytes(StandardCharsets.UTF_8));
HttpURLConnection postConnection =(HttpURLConnection)url.openConnection();
postConnection.setRequestMethod("POST")
postConnection.setDoInput(true)
postConnection.setRequestProperty( "Authorization", "Basic ${encoded}" );
postConnection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
postConnection.setRequestProperty("Accept", "application/json");
postConnection.setDoOutput(true);
postConnection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, request) }

log.error(postConnection.getResponseCode())
log.error(postConnection.getResponseMessage())
postConnection.connect()
log.error(postConnection.getResponseCode())
log.error(postConnection.getResponseMessage())

 The logs are as follows:

2020-03-27 12:04:39,588 ERROR [runner.AbstractScriptRunner]: 500
2020-03-27 12:04:39,588 ERROR [runner.AbstractScriptRunner]:
2020-03-27 12:04:39,588 ERROR [runner.AbstractScriptRunner]: 500
2020-03-27 12:04:39,588 ERROR [runner.AbstractScriptRunner]:

 

1 answer

1 accepted

0 votes
Answer accepted

Hi @Sam ,

Can you please take a look at the documentation again as it has recently been updated due to an error in the Payload description.

Can you please use "name" : " your_members_name"

instead of "key": "userkey"

Regards,
Susanne Götz
Tempo team

Hello Susanne,

Thank you for your response! I have edited the code to the following, but I still get the exact same error. When you mentioned the documentation, is this what you were talking about: https://www.tempo.io/server-api-documentation/teams#operation/getTeamMembers

import com.atlassian.jira.component.ComponentAccessor;
import java.nio.charset.StandardCharsets;
import groovy.json.StreamingJsonBuilder;
import groovy.json.JsonSlurper;

def jsonSlurper = new JsonSlurper();
def url = new URL("https://tracking-dev.ainq.com/rest/tempo-teams/2/team/67/member");
String encoded = Base64.getEncoder().encodeToString((username+":"+password).getBytes(StandardCharsets.UTF_8));
HttpURLConnection postConnection =(HttpURLConnection)url.openConnection();
postConnection.setRequestMethod("POST")
postConnection.setRequestProperty("Content-Type", "application/json; utf-8");
postConnection.setRequestProperty("Accept", "application/json");
postConnection.setDoOutput(true);

def jsonInputString = '''
{
"member": {
"type": "USER",
"name": "svanfossen"
},
"membership": {
"role": {
"id": 1
},
"dateFrom": "",
"dateTo": "",
"availability": "100"
}
}
'''
postConnection.setRequestProperty( "Authorization", "Basic ${encoded}" );
postConnection.requestMethod = "POST";
postConnection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
postConnection.setRequestProperty("Accept", "application/json");
postConnection.setDoOutput(true);
postConnection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, jsonInputString) }
postConnection.connect();

Hi @Sam

The documentation I am referring to is for the "Add a member to a team" API ( https://www.tempo.io/server-api-documentation/teams#operation/addMember) ( which is the API you are using.

Can you please try to use this API outside of your script ( f.x using Postman) and check if you can add a user to the team directly. Please note that adding users via API requires the same permissions as when adding the user in the UI, so you will need to make sure that the authenticated user has the "Tempo Team Administrator" permission. 

Regards,
Susanne

Hi @Susanne Götz , 

I haven't tried the API outside of my script, although I'm not sure why it wouldn't work in that context. I've contacted members of my team about using an API platform.

I've also verified that I do have the "Tempo Team Administrator" permission, so it doesn't seem like that's the issue.

@Sam 

It might be useful to know if it is the API that is causing the problem or if it is within a different part of the script. 

Regards,
Susanne

@Susanne Götz , it works outside of ScriptRunner, so it looks like the problem is with ScriptRunner. Thanks for your help!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New Cloud Apps Roundup - Spring 2021

Atlassian's marketplace partners have had a very productive start to 2021! Since our last roundup, our developer community has added over 160 new cloud apps to the Atlassian Marketplace to help you...

208 views 3 20
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you