c# creat portal user

André Höfgen May 5, 2017

hi,

i would like to import our it-emails from user via a windows service directly into jira. so far so good. the windows service is working fine.

 

from the licence model: jira differenciats between full user (needs a licence) and portal user (free of licence). my problem is that i would like to create via c# protal-user for the user which are reporting a case, but do not have / need a full licence.

i've found in the sdk so far only the class JiraUser. but it creats me "full-licenced-users".

 

has anyone an idea how to manage this?

 

thanks.

 

br, andre

2 answers

1 accepted

0 votes
Answer accepted
André Höfgen May 7, 2017

hi @all,

finally i could manage it. my code was fine as well as the data in "theory". json-checker said data was fine. but not for jira.

in the mentioned link to jira-REST-api-customer, jira is presenting an example how json should look like to create a customer:

{"displayName": "string","email": "string","fullName": "string"}

in my IDE i got all the time as an answer to my POST-request "StatusCode: 400, Bad request", but not more.

I heared in a tutorial about the tool POSTMAN, where you can create JSON request to any api. very nice. here i finally got a usable answer >>> "you cannot use displayName and fullName at the same time"

reducing my JSON-data to {"displayName": "string","email": "string"} made my code working.

 

thanks again to the makers of POSTMAN, you saved my day. :)

 

br, andre

 

0 votes
Maarten Cautreels
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 Leaders.
May 5, 2017

Hi André,

Luckily you can since they've recently resolved this suggestion: JSDCLOUD-3398.

There's an API especially for this task: https://developer.atlassian.com/cloud/jira/service-desk/rest/#api-customer-post

Hope this helps,

Maarten

André Höfgen May 5, 2017

thanks fo you quick answer. i'll try it asap. but i never used REST before. it might get a bit tricky for me. ;)

do you know, if they will implement this functionality also in the .net-sdk

 

br, andre

André Höfgen May 6, 2017

hi, i managed it so far to get users via webRequest/JSON. but when i try to create a user, i get always as response "StatusCode:400 - Bad Request". the new user is defenetly not in the database. but the response does not contain a helpful advice. below my relevant c# code - any idea what i#m doing wrong?

thanks.

br, andre

 

client.BaseAddress = new Uri(url_BaseAddress);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Add("Authorization", " Basic " + base64EncodedCredentials);
client.DefaultRequestHeaders.Add("Accept", "application/json");

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url_Customer_Create);

jsonStr = JsonConvert.SerializeObject(customer);//json string checked via webtool > is OK

request.Content = new StringContent(jsonStr, Encoding.ASCII, "application/json");

using (HttpResponseMessage response = await client.SendAsync(request))
{
if (response.IsSuccessStatusCode)
{
      //some more code...

}
}

Suggest an answer

Log in or Sign up to answer