Hi K2 mates,
I am getting Method not found error while doing REST API call to start workflow. Need Help. Sharing my ode below. Kindly advise
string BaseK2Uri = @"https://k2d.xxx.com/K2Services/REST.svc";
string ProcessStartRestUrl = @"Process/Definitions(globalit_B_Change Request Workflow)/StartInstance";
//Build up a XML string to send to rest service
StringBuilder sb = new StringBuilder();
sb.Append(@"<?xml version='1.0' encoding='utf-8'?><w:ProcessInstance xmlns:w='http://schemas.k2.com/worklist/d1' xmlns:p='http://schemas.k2.com/process/d1'");
sb.Append(@"FullName='GlobalITChange Request Workflow'");
sb.Append(" Folio='" + requestID + "'");
sb.Append(" Priority='1'>");
// datafields
sb.Append("<p:DataField Name='ID'>" + changeRequest.ID + "</p:DataField>");
sb.Append("<p:DataField Name='Change Request ID'>" + requestID + "</p:DataField>");
sb.Append("<p:DataField Name='Requestor Name'>" + changeRequest.CreatedBy + "</p:DataField>");
sb.Append("<p:DataField Name='Requestor Email'>" + GetCurrentUserDetails().EmailId + "</p:DataField>");
sb.Append("<p:DataField Name='Requestor ID'>" + GetCurrentUserDetails().UserName + "</p:DataField>");
sb.Append("<p:DataField Name='Role ID'>" + changeRequest.RoleID + "</p:DataField>");
sb.Append("<p:DataField Name='Functional Area'>HR Operations</p:DataField>");
sb.Append("<p:DataField Name='ID_Planning'>" + changeRequest.PlanningID + "</p:DataField>");
sb.Append("<p:DataField Name='Key User Email'>" + GetCurrentUserDetails().EmailId + "</p:DataField>");
sb.Append("<p:DataField Name='Key User Name'>" + GetCurrentUserDetails().UserName + "</p:DataField>");
sb.Append("</w:ProcessInstance>");
// post XML to process service
System.Threading.Tasks.Task<HttpResponseMessage> response;
System.Net.Http.HttpClientHandler handler = new HttpClientHandler();
CredentialCache cache = new CredentialCache();
handler.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
{
using (HttpClient client = new HttpClient(handler))
{
string resourceAddress = ProcessStartRestUrl;
//if you want to start sync, append ?synchronous=true to the URL;
client.BaseAddress = new Uri(BaseK2Uri + "/");
//start an async call to the service. Normally you would use more advanced threading for this approach
response = client.PostAsync(resourceAddress, new StringContent(sb.ToString(), Encoding.UTF8, "text/xml"));
response.Wait();
if (!response.Result.IsSuccessStatusCode)
{
throw new Exception(response.Result.StatusCode.ToString());
}
}
}