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 :) 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
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 19, 2022

issue resolved. I replaced the body to 

 
def body = "{\"name\":\"sampleuser\",\"password\":{\"value\":\"secret\"},\"active\":true,\"first-name\":\"Sample\",\"last-name\":\"User\",\"display-name\":\"SampleUser\",\"email\":\"sample@user.cool\"}"
TAGS
AUG Leaders

Atlassian Community Events