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

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.

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
    {
        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.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,816 views 11 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot