Componenet creatation failed with 404 in C# and REST

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.

3 answers

0 votes
Pedro Cora Atlassian Team Jul 22, 2013


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.

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.

can you share your code?

public enum JiraResource
public class JiraRestSvc
        private const string m_BaseUrl = "http://localhost:8080/rest/api/2/";

        // Greenhopper REST API
        // 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()))

            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\"}";

                string resp_json = RunQuery(JiraResource.component, null, post_json, "POST");
            catch (Exception ex)

I would like to create component under existing project with key "TEST", and it failed.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,381 views 15 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you