not able to consume Create Project from c#

Hello Team,

I'm trying to create project on jira from my c# code and it is not working but when i used postman to create projcet, it create the project on jira.

Please suggest me something i reach bottleneck

1 answer

0 vote
Sam Hall Community Champion May 10, 2017

Hi Harry - to get a decent answer, you'll need to share a bit more information here.

What are you expecting to happen and what is actually happening. Are you getting an error message? If so post the details. 

If you can share a snippet of the code you are using which shows how you are calling the API, it will help people understand what you are trying to do.

Finally, since your question is development related, consider asking it over on the dedicated developer's community: https://community.developer.atlassian.com. If you do that, post a link here so that others can follow the trail.

Below is the code :-

NewProject objnewprj = new NewProject();
objnewprj.key = "TEST";
objnewprj.name = "TEST";
objnewprj.projectTypeKey = "business";
objnewprj.projectTemplateKey = "com.atlassian.jira-core-project-templates:jira-core-project-management";
objnewprj.description = "Example Project description";
objnewprj.lead = "admin";
objnewprj.url = "http://abc.co.in/";
objnewprj.assigneeType = "UNASSIGNED";
objnewprj.avatarId = 10204;
objnewprj.issueSecurityScheme = 10000;
objnewprj.permissionScheme = 10100;
objnewprj.notificationScheme = 10100;
objnewprj.categoryId = "10000";
var projectitem = new JavaScriptSerializer().Serialize(objnewprj);
byte[] formbytes = System.Text.ASCIIEncoding.Default.GetBytes(projectitem.ToString());

var webrequest = (HttpWebRequest)WebRequest.Create("http://jirademoseasia.atlassian.net/rest/api/2/project");
webrequest.Method = "POST";
webrequest.ContentType = "application/json";
webrequest.UserAgent = "xx";
try
{
var webresponse = webrequest.GetResponse();
System.IO.StreamReader reader = null;
System.IO.Stream responseStream = webresponse.GetResponseStream();
reader = new System.IO.StreamReader(responseStream);
result = reader.ReadToEnd();
}
catch(Exception ex)
{
return "error";
}
return result;

 

This implementation is working fine on Postman Software but when implementing through code giving "The remote server returned an error: (400) Bad Request." error.

One thing the url specified here is dummy and you have to provide some actual url here to run thid code.

Please review the code and give your valuable feedback.

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 yesterday in Agile

What is ChatOps? A guide to its evolution, adoption, and significance

I am the product of AIM. I can hear that door swinging open and closed in my mind with absolute fidelity. I’d recognize that ding anywhere. At 15, as I typed away into AOL IM, I never imagined that ...

47 views 1 6
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