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

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
Community showcase
Posted 8 hours ago in United States

Confluence Security Advisory

Good morning Members, Not sure if you are aware. Please read the following: https://www.icloud.com/keynote/0RyJ4VEdNUpjDpGfMhfZx9fEg#Confluence_Security_Advisor More details: https://co...

24 views 1 0
View post

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