I am implementing REST API of JIRA to create a new project using C# language. I am using the following code:
NewProject objnewprj = new NewProject();
objnewprj.key = "key";
objnewprj.name = "Testing Project";
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;
It is working fine for REST client but in code i am getting the issue
"The remote server returned an error: (400) Bad Request."
Any help?
The documentation says:
Status 400 - Returned if the request is not valid and the project could not be created.
I have created a POST request using Insomnia to create a project with the same body as yours:
{"key":"key",
"name":"Testing Project",
"projectTypeKey":"business",
"projectTemplateKey":"com.atlassian.jira-core-project-templates:jira-core-project-management",
"description":"Example Project description",
"lead":"admin",
"url":"abc.co.in/",
"assigneeType":"UNASSIGNED",
"avatarId":10204,
"issueSecurityScheme":10000,
"permissionScheme":10100,
"notificationScheme":10100,
"categoryId":"10000" }
It gives me interesting results:
{
"errorMessages": [],
"errors": {
"projectKey": "Project keys must start with an uppercase letter, followed by one or more uppercase alphanumeric characters.",
"projectUrl": "The URL specified is not valid - it must start with http://"
}
}
I have also noticed that the JSON you pasted in your comment is wrong (there is an ;
after the url parámeter). Please review the server response in order to find a more detailed messsage about the project creation problems.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.