Add project through API in JIRA by .net application

Binu George January 5, 2016


Hi All
         I trying to create one project in JIRA through API by ASp.net Application. Below i giving my code. I not getting any exception. But Not adding project to JIRA. Where i doing mistake?





 string url = "https://actjira.atlassian.net/rest/api/2/project";
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.ContentType = "application/json";
            
            request.Method = "POST";
            string base64Credentials = GetEncodedCredentials();
            request.Headers.Add("Authorization", "Basic " + base64Credentials);
            request.ContentLength = data.Length;
            try
            {
                using (var reqStream = request.GetRequestStream())
                using (StreamWriter writer1 = new StreamWriter(reqStream))
                {
                    writer1.Write(data);
                }
            }
            catch (Exception e1)
            {
                throw e1;// error handling code
            }




 private string GetEncodedCredentials()
        {
            string mergedCredentials = string.Format("{0}:{1}", "username", "password");
            byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
            return Convert.ToBase64String(byteCredentials);
        }

 


I reffered below url
https://docs.atlassian.com/jira/REST/latest/#api/2/project-createProject and Passing data

2 answers

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 5, 2016

You appear to be calling the create function without giving it any data.

Binu George January 6, 2016

Hi Nic Brough Thanks for your response. I passing data in same format below mentioned url. I not able to give here that format here i getting error when i click button https://docs.atlassian.com/jira/REST/latest/#api/2/project-createProject string data= "\"fields\": { \"project\": { \"id\": \"TJI\" }, \"description\": \"Hellow why doesn't this work\", \"summary\": \"REST ye merry gentlemen.\", \"issuetype\": { \"name\": \"Bug\" } } ";

Binu George January 6, 2016

string data passing to API

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 6, 2016

The fields in there are for issue creation/update, not project. Try sending it the correct data format, as listed in the link you've given.

Binu George January 6, 2016

string data = "{\"key\": \"EX1\",\"name\": \"Example1\",\"projectTypeKey\": \"software\",\"description\": \"Example Project description\",\"url\": \"http://actjira.atlassian.net\"}" I tried this. But not working

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 6, 2016

Ok, is EX1 a valid project key in your system? What error message / response are you getting to this call?

Binu George January 6, 2016

I try to create new project with this key. I not getting any error message or response But when i debug my code below mentioned code executing using (var reqStream = request.GetRequestStream()) using (StreamWriter writer1 = new StreamWriter(reqStream)) { writer1.Write(data); }

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 6, 2016

There's always a response of some sort, unless the call works, so my best guess is that your code is not actually performing the call, or it's not processing the response. I can't help you with your .net code, I don't use it.

Binu George January 6, 2016

Are you able to say what are the possibility of non performing call?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 6, 2016

Start by ignoring your code. On a command line, try a simple "curl" call to create the project (have a look at the example code in the docs for doing that). That will always give you a response of some sort. If it fails, you'll get an error telling you why. If it works, then you know your code is not performing the call.

Binu George January 6, 2016

How make REST API option enable in Jira ?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 6, 2016

If you're on Server, check Admin -> General Settings -> Remote API is enabled (it is on by default) If you're on Cloud, then it's enabled.

Binu George January 6, 2016

Toady i getting error message from Jira when i try to add project. That messge i giving below StatusCode: MethodNotAllowed, Content-Type: text/html;charset=UTF-8, Content-Length: 0 whats meaning of this?

0 votes
HarryH
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 Leaders.
January 5, 2016

Please make sure REST API option is enabled in JIRA.

 

 

Binu George January 5, 2016

How can i check that? . I getting response from API.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events