Forums

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

Can't add users to crowd with rest API, getting Internal Server Error 500

Basel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 14, 2022
import.java.net.HttpURLConnection
import java.net.URL
import java.util.Base64

URL url = new URL(http://crowd:8095/crowd/rest/usermanagement/1/user
con.setRequestMethod("POST")

def password = "password"
def username = "username"
def userpass = username + ":" + password
def basicAuth = "Basic:" + new String(Base64.getEncoder().encode(userpass.getBytes())

con.setRequestProperty("Authorization", basicAuth)
con.setRequestProperty(Content-Type", application/json; utf-8)
con.setRequestProperty("Accept", aplication/json)
con.setRequestProperty("Cache-Control","no-cache")
con.setRequestProperty("X-Atlassian-Token", "no-check")

con.SetDoOutput(true)
def body = "{\"name\": \"sampleuser\",\"password\":\"secret\",\"first-name\":\"sample\",\"last-name\":\"user\",\"display-name\":\"Sample User\",\"email\":\"sampleuser@user.cool\"}"

OutputStream os = con.getOutputStream()
byte[] input = body.getBytes("utf-8")
os.write(input,0,input.length)

log.warn(con.getResponseCode)
log.warn(con.getResponseMessage)
con.disconnect()
I've written the script as above, which should add a user crowd. However, when it runs I get response code 500 "Internal Server Error".
Any help would be appreciated thanks :) 

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Serj Shcherbakov
Contributor
May 27, 2018

Hi Thanos,
Your solution does not works: now assignee field does not populate on creation form,
PFA:

new.jpg

0 votes
Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
May 25, 2018

Hi Сергей,

The id of the assignee field is wrong, and since you already import the IssueFieldConstants (good practice) then 

def assignee = getFieldById(ASSIGNEE)

Regards, Thanos

TAGS
AUG Leaders

Atlassian Community Events