Add project through API in JIRA by .net application


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

Please make sure REST API option is enabled in JIRA.

 

 

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

0 vote

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

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

string data passing to API

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.

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

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

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); }

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.

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

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.

How make REST API option enable in Jira ?

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.

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?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

119 views 0 5
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