The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

RESP API call using c# to remove a user from a group

Timothy Kidd
August 1, 2018

I see many references online to use:

curl -X POST -d {"name":"groupname"} -ik -u application:password -H 'Content-Type: application/json' -H 'Accept: application/json' https://localhost/crowd/rest/usermanagement/1/user/group/direct?username=username --cookie cookies.txt

curl -i -u application_name:application_password --data '{"value": "my_password"}' http://localhost:8095/crowd/rest/usermanagement/1/authentication?username=my_username --header 'Content-Type: application/json' --header 'Accept: application/json' --cookie-jar cookies.txt

 

However, when I try to access the same REST using C# code it does not work.  I have tried many variation of the code including changing it from "Post" to "DELETE".  Any assistance would be greatly appreciated.

 

string url = "https://jira-ta-test.allstate.com/crowd/rest/usermanagement/1/user/group/direct?username=bashi";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
var request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/json";
request.Method = WebRequestMethods.Http.Post;
string ttt = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes("xxxx" + ":" + "xxxx"));
request.Headers["Authorization"] = "Basic" + " " + ttt;

using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
//string json = "{\"key\":\"value\"}";
string json = "{\"name\":\"jira-testers\"}";
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}

var httpResponse = (HttpWebResponse)request.GetResponse();

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Timothy
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.
August 1, 2018

Are you calling Jira or calling Crowd? Your URL endpoint is for Crowd but you tagged this question as Jira.

This is the Crowd API:

This is the Jira API:

Timothy Kidd
August 1, 2018

It is for JIRA and it didn't work for JIRA either.  I have used the reference you pointed to but wouldn't work so I started to google and try all different codes.  

Timothy
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.
August 2, 2018

This is the code from Postman and it works for me:

var client = new RestClient("http://localhost:8080/jira/rest/api/2/group/user?groupname=test&username=admin");
var request = new RestRequest(Method.DELETE);
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
IRestResponse response = client.Execute(request);
Timothy Kidd
August 3, 2018

It keeps returning "403 - Forbidden" Error message.  The id that I am using is an admin account.  I have tried every variation that I can think of and it simply returns 403 Error.  The same code that uses "GET" or "POST" methods works fine, just the "DELETE" method does not work.  I am going crazy here.

string url = "https://jira-ta-test.allstate.com/jira/rest/api/2/group/user?groupname=JS-Admins&username=xxxx";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
var request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/json";
request.Accept = "application/json";
request.Method = "DELETE";
request.Headers.Add("Cache-Control", "no-cache");
string ttt = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes("xxx" + ":" + "xxx"));
request.Headers["Authorization"] = "Basic" + " " + ttt;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();