Create Project Area using Rest API c# dotnet
![]() (Sorry for my not so great English skills)
Hey guys,
I am trying to create a service that creates project areas in multiple aplications.
I am always getting the error 400, because of the body. I dont understand why. I think i fullfill the requirements.
Here is the code.
public static void Create_Proj_area()
{
try
{
string server = "https://localhost:9443/ccm";
//first sample string from Jazz wiki
//formalpm.process.ibm.com
string xml_content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<jp06:project-area xmlns:jp06=\"http://jazz.net/xmlns/prod/jazz/process/0.6/ \" jp06:name=\" testProjectAreaCreation \" jp06:templateId=\"formalpm.process.ibm.com\" jp06:templateLocale=\"en_US\"" +
"<jp06:summary>The summary does not contain anything</jp06:summary>" +
"<jp06:description>Dummy project area</jp06:description>" +
"<jp06:visibility jp06:access=\"PUBLIC\"/>" +
"<jp06:members xmlns:jp06=\"http://jazz.net/xmlns/prod/jazz/process/0.6/ \">" +
"<jp06:member>" +
"<jp06:user-url>https://localhost:9443/jazz/users/master</jp06:user-url>" +
"</jp06:member>" +
"</jp06:members>" +
"</jp06:project-area>";
string url = "https://localhost:9443/ccm/process/manageProjectAreas";
string mediatype = "application/xml;Charset=UTF-8";
CookieContainer cookies = GetCookiesContainer();
HttpWebRequest formPost = (HttpWebRequest)WebRequest.Create(server + "/j_security_check");
formPost.Method = "POST";
formPost.Timeout = 30000;
formPost.CookieContainer = cookies;
formPost.ContentType = "application/x-www-form-urlencoded";
String output = "j_username=" + login + "&j_password=" + password;
Byte[] outputBuffer = Encoding.UTF8.GetBytes(output);
formPost.ContentLength = outputBuffer.Length;
Stream stream = formPost.GetRequestStream();
stream.Write(outputBuffer, 0, outputBuffer.Length);
stream.Close();
HttpWebResponse formResponse = (HttpWebResponse)formPost.GetResponse();
string header = formResponse.Headers[AUTHREQUIRED];
if ((header != null) && header.Equals("authfailed"))
{
// The login failed
throw new WebException("Authentication failed");
}
else
{
formResponse.GetResponseStream().Flush();
formResponse.Close();
}
string catalog = "https://localhost:9443/ccm/process/project-areas";
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(catalog);
webRequest.Method = "POST";
//webRequest.Headers.Add("X-Jazz-CSRF-Prevent", "here session id");
//webRequest.PreAuthenticate = true;
//webRequest.Headers.Add("Authorization", "Basic " + token);
webRequest.KeepAlive = true;
webRequest.Referer = server;
webRequest.CookieContainer = cookies;
webRequest.ContentType = "text/xml";
webRequest.Accept = "application/xml";
var parameterString = Encoding.UTF8.GetBytes(xml_content);
webRequest.ContentLength = parameterString.Length;
using (var buffer = webRequest.GetRequestStream())
{
buffer.Write(parameterString, 0, parameterString.Length);
buffer.Close();
}
System.Net.WebResponse tempResponse = webRequest.GetResponse();
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
}
}
|
One answer
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.