Hi there,
I am using REST API and C# to create a component under a project, but it fails with 404 error.
I used RESTClient, an add-on for firefox to verify the problem and found the response is 404 and "No project could be found with key xxxx". The project key indeed exists in JIRA.
Could someone kindly tell me any hints?
Thank you.
public enum JiraResource { project, issue, component, workflow, workflowscheme, group, groups } public class JiraRestSvc { private const string m_BaseUrl = "http://localhost:8080/rest/api/2/"; // Greenhopper REST API // https://jira.atlassian.com/plugins/servlet/restbrowser#/com-pyxis-greenhopper-jira-greenhopper-rest-filter // http://localhost:8080/rest/greenhopper/1.0/project-list private string m_Username; private string m_Password; public JiraRestSvc(string username, string password) { m_Username = username; m_Password = password; } private string GetEncodedCredentials() { string mergedCredentials = string.Format("{0}:{1}", m_Username, m_Password); byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials); return Convert.ToBase64String(byteCredentials); } protected string RunQuery(JiraResource resource, string argument = null, string data = null, string method = "GET") { string url = string.Format("{0}{1}/", m_BaseUrl, resource.ToString()); if (argument != null) { url = string.Format("{0}{1}/", url, argument); } HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.ContentType = "application/json"; request.Method = method; if (data != null) { using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write(data); } } string base64Credentials = GetEncodedCredentials(); request.Headers.Add("Authorization", "Basic " + base64Credentials); HttpWebResponse response = request.GetResponse() as HttpWebResponse; string result = string.Empty; using (StreamReader reader = new StreamReader(response.GetResponseStream())) { result = reader.ReadToEnd(); } return result; } public void CreateComponent() { string post_json = "{\"name\": \"Test Component\", \"description\": \"This is a test component from program\", \"leadUserName\": \"xxx\", \"asigneeType\": \"PROJECT_LEAD\", \"isAssigneeTypeValid\": false, \"project\": \"TEST\"}"; try { string resp_json = RunQuery(JiraResource.component, null, post_json, "POST"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
I would like to create component under existing project with key "TEST", and it failed.
Hi Pedro,
I am using a unique account which administers JIRA, so this problem should not be caused by permission limitation. How do you think? Any other clues?
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you share your code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ben,
Check if the user logging in to retrieve the REST call has permissions to browse the issues through the interface. This user must be in the Browse Project permission in the project's Permission Scheme.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.