DISCLAIMER: This is a fork from the original project https://github.com/jlucansky/Camunda.Api.Client! I made changes to be able to build it on my MAC and also added some new features.
Camunda REST API Client for .NET platform
- .NET Framework 4.6.1
- .NET Standard 2.0
Each part listed below is fully covered according to https://docs.camunda.org/manual/7.9/reference/rest specification.
- Case Definition
- Case Execution
- Case Instance
- Decision Definition
- Decision Requirements Definition
- Deployment
- Execution
- External Task
- Group
- History / Activity Instance
- History / Case Definition
- History / Case Instance
- History / Case Activity Instance
- History / Decision Instance
- History / Decision Requirements Definition
- History / Detail
- History / Incident
- History / Job Log
- History / Process Instance
- History / Variable Instance
- Incident
- Job
- Job Definition
- Message
- Process Definition
- Process Instance
- Signal
- Task
- Tenant
- User
- Variable Instance
The Camunda REST API Client is available on nuget.org
To install Camunda REST API Client, run the following command in the Package Manager Console
PM> Install-Package Camunda.Api.Client
CamundaClient camunda = CamundaClient.Create("http://localhost:8080/engine-rest");
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("http://localhost:8080/engine-rest");
httpClient.DefaultRequestHeaders.Add("Authorization", "Basic ZGVtbzpkZW1v");
CamundaClient camunda = CamundaClient.Create(httpClient);
// build query
var externalTaskQuery = new ExternalTaskQuery() { Active = true, TopicName = "MyTask" };
// add some sorting
externalTaskQuery
.Sort(ExternalTaskSorting.TaskPriority, SortOrder.Descending)
.Sort(ExternalTaskSorting.LockExpirationTime);
// request external tasks according to query
List<ExternalTaskInfo> tasks = await camunda.ExternalTasks.Query(externalTaskQuery).List();
// get all external tasks without specifying query
List<ExternalTaskInfo> allTasks = await camunda.ExternalTasks.Query().List();
VariableResource vars = camunda.ProcessInstances["0ea218e8-9cfa-11e6-90a6-ac87a31e24fd"].Variables;
// set integer variable
await vars.Set("Var1", VariableValue.FromObject(123));
// set content of binary variable from file
await vars.SetBinary("DocVar", new BinaryDataContent(File.OpenRead("document.doc")), BinaryVariableType.Bytes);
var executionId = "290a7fa2-8bc9-11e6-ab5b-ac87a31e24fd";
// load all variables of specified execution
Dictionary<string, VariableValue> allVariables = await camunda.Executions[executionId]
.LocalVariables.GetAll();
// obtain strongly typed variable with name Var1
int myVar1 = allVariables["Var1"].GetValue<int>();
HttpContent fileContent = await camunda.Executions[executionId]
.LocalVariables.GetBinary("file1");
using (fileContent)
{
using (var outStream = File.OpenWrite("file1.doc"))
{
(await fileContent.ReadAsStreamAsync()).CopyTo(outStream);
}
}
var msg = new CorrelationMessage() { All = true, MessageName = "TestMsg" };
msg.ProcessVariables
.Set("Date", DateTime.Today)
.Set("ComplexVar", new { abc = "xyz", num = 123});
// correlate message with process variables
await camunda.Messages.DeliverMessage(msg);
// deploy new bpmn diagram with some attachment
await camunda.Deployments.Create("My Deployment 1",
new ResourceDataContent(File.OpenRead("C:\\diagram.bpmn"), "diagram.bpmn"),
new ResourceDataContent(File.OpenRead("C:\\document.doc"), "document.doc"));
// get all jobs owned by Process_1 with DueDate in the future
var jobQuery = new JobQuery() { ProcessDefinitionKey = "Process_1" };
jobQuery.DueDates.Add(new ConditionQueryParameter()
{
Operator = ConditionOperator.GreaterThan, Value = DateTime.Now
});
var jobs = await camunda.Jobs.Query(jobQuery).List();
This project is made available under the MIT license. See LICENSE for details.