Edit and Delete the JIRA component name

How to edit and delete the JIRA component name by using REST API in a console application (c#)?

1 answer

0 votes

Your application should use the Component REST API to update/delete the components.

Hi Nic,

I have following doubts,

  1. I don`t know where I have to use PUT /rest/api/2/component/{id}
  2. Also, how do I find the {id} for the particular component?
  3. Is any possibilities available to edit/remove the component by using project key?

 

I used to add a new component by below coding: 

 class Program
    {
        private const string URL = "https://xyz.atlassian.net/rest/api/2/component";
        private const string DATA = @"{""name"": ""sample Component"",
                                       ""description"": ""This is a JIRA component"",
                                       ""leadUserName"": ""Sample manager"",
                                       ""assigneeType"": ""PROJECT_LEAD"",
                                       ""isAssigneeTypeValid"": false,
                                       ""project"": ""TP""}";
        static void Main(string[] args)
        {
            try
            {
                AddComponent();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadKey();
            }
            Console.WriteLine("Component Added");
            Console.ReadLine();
        }
        private static void AddComponent()
        {
            try
            {
                System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
                client.BaseAddress = new System.Uri(URL);
                byte[] cred = UTF8Encoding.UTF8.GetBytes("username:password");
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                System.Net.Http.HttpContent content = new StringContent(DATA, UTF8Encoding.UTF8, "application/json");
                HttpResponseMessage messge = client.PostAsync(URL, content).Result;
                string description = string.Empty;
                if (messge.IsSuccessStatusCode)
                {
                    string result = messge.Content.ReadAsStringAsync().Result;
                    description = result;
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }

 

Regards,

Arunkumar

  1.  The PUT is required to tell JIRA that you are posting data over.
  2. Try a GET  http://yourserver/rest/api/2/project/<project id>/components  - that should list them all out for that project
  3. No, you need to use the component calls.

I mean how can I use the PUT to update the component and DELETE to delete the component?

Is above link is right to update/delete the component? if wrong means kindly revert it!

 

thanks in advance.

 

No, you have not read the docs, and you're inventing nonsense urls now. 

Please use the urls that are documented.  The put/get/delete commands are commands, not something you randomly insert in a url.  And, as we've already discussed, your first url is the wrong url for accessing components.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Friday in Jira Service Desk

Looking for anyone who has switched from Zendesk to Jira Service Desk

Hi Community! The Jira Service Desk marketing team is looking for customers who have successfully switched from Zendesk to Jira Service Desk!   We’d love to hear your thoughts on the pros and ...

47 views 2 2
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