Problem with the APIs for creating new customer

Hi there,

I’m trying to call the url “http://cloudname.atlassian.net/rest/servicedeskapi/customer” in VB.NET for creating a new customer. It returns the HTTP-Failure 400. The code for this looks like:

        Dim requestCustomer As HttpWebRequest = WebRequest.Create("https://cloudname.atlassian.net/rest/servicedeskapi/customer")
        With requestCustomer
            .CookieContainer = SessionCookies
            .Method = "POST"
            .Headers.Set("X-ExperimentalApi", "true")
            .ContentType = "application/json"
        End With

        Dim newCustomer = "{""email"":""yagmur@test.com"",""displayName"":""Yagmur""}"
        Dim newCustBytes = Text.Encoding.Default.GetBytes(newCustomer)
        requestCustomer.ContentLength = newCustBytes.Length
        Dim requestStream = requestCustomer.GetRequestStream()
        requestStream.Write(newCustBytes, 0, newCustBytes.Length)
        requestStream.Close()

        Dim responseCustomer As HttpWebResponse = requestCustomer.GetResponse()
        Dim streamReaderCust As New IO.StreamReader(responseCustomer.GetResponseStream)
        Dim responseStreamCust = streamReaderCust.ReadToEnd
        streamReaderCust.Close()
        responseCustomer.Close()

What am I missing there? Is there a way to set the password for the customer by creating?

HTTP error code 400 is returned if the username (email) already exists; could that be the problem?

Also, I can’t see where you are setting authentication credentials (basic auth or whatever). Maybe you have that covered, but I’m not a VB.NET guy.

The response should contain details about what was wrong with the request. It can look like this:

{
  "errorMessage": "This request is invalid. Check that the request contains all the required parameters and that the parameters are valid. (username : A user with that username already exists.)",
  "i18nErrorMessage": {
    "i18nKey": "sd.rest.error.bad.request.with.extra.info",
    "parameters": [
      "username : A user with that username already exists."
    ]
  }
}

Please check it out or paste it here.

Re your second question. You cannot set a password using REST API. Please look also at https://docs.atlassian.com/jira-servicedesk/REST/cloud/#servicedeskapi/customer-createCustomer where you can find:

“They can set a password by clicking “Forgotten your password” on the portal login screen, or a JIRA administrator can set one in User Management.”

The username does not exist or it is not shown after listing all usernames, I will check this out. And the authentication is the basic auth, where I set the credentials on this line:

        .CookieContainer = SessionCookies

The SessionCookies contain the JSESSIONID and the cloud.session.token, which are send by the response after the authentication. This can not be the problem because I can create new organizations.

Thanks for the response detail. I checked the stream of the error response and yes the user already existed, where I was sure that the user has been deleted (does not exist).

The weird thing was that I could not see the created the user on the cloud webpage of the given service desk project, after deleting the organization where the user existed. And this user was also not listed in the HTTP request for showing all the customers of the service desk. Also creating the user again on the cloud by hand did not show any messages that the user already existed. These points confused me however I know now what it was. Thank you all!

Re setting password by REST API. Will be there an option for this feature in the near future?

The way that JIRA Service Desk (JSD) presents information about customers and users can be confusing. There’s the customer list against particular projects, and then there’s the User Management section in the Administration area - even there, users are not listed unless you select the ‘Restricted portal access’ (or something like that) option. The way I typically remove all trace of a customer is by executing this command from a Terminal window:

http --auth <username:password> --pretty all DELETE https://jirainstancedomainname.blah/rest/api/2/user username==joe.bloggs@example.com

The http command is provided by https://httpie.org in this case.

Thank you for the tipp! This will help to really delete them!