Step 2: Running Workflows from Code
So far, we have seen how to compose and run basic workflows from the UI. However, more commonly, we will be running the workflows from an application or service. Let’s learn how to do this from our applications. Orkes Conductor platform offers various SDKs in different languages for integration with applications or services.
View our documentation on Conductor Clients & SDKs to learn how to import the required dependencies in our applications.
Let's look at some code examples of how to trigger a workflow by its name. We have also linked the repository where this code sample is hosted. To test these ourselves, we can also clone them locally and try them out.
- Java
- Python
- Go
- C#
- JavaScript
- Clojure
StartWorkflowRequest request = new StartWorkflowRequest();
request.setName("deposit_payment");
Map<String, Object> inputData = new HashMap<>();
inputData.put("amount", depositDetail.getAmount());
inputData.put("accountId", depositDetail.getAccountId());
request.setInput(inputData);
String workflowId = workflowClient.startWorkflow(request);
log.info("Workflow id: {}", workflowId);
request = StartWorkflowRequest(
name="<name of your workflow>",
input={
"amount": 100,
"account": "<account-id>"
},
)
workflow_id = workflow_client.start_workflow(
body=start_workflow_request,
)
print(f'Workflow id: {workflow_id}')
request := model.NewStartWorkflowRequest(
"<name of your workflow>",
1,
"",
map[string]interface{}{
"amount": 100,
"account": "<account-id>"
}
)
workflowId, err := workflowExecutor.StartWorkflow(
request,
)
log.info("Workflow id: ", workflowId)
var request = new StartWorkflowRequest
{
Name = WORKFLOW_NAME,
Version = WORKFLOW_VERSION,
Input = Examples.Util.TypeUtil.GetDictionaryFromObject(depositDetail)
};
var workflowId = _workflowClient.StartWorkflow(request);
Console.WriteLine($"Started deposit workflow id: {workflowId}");
return workflowId;
const request: StartWorkflowRequest = {
name: "<name of your workflow>",
version: 1,
input: {
"amount": 100,
"account": "account-id"
}
}
const workflowId = client.workflowResource.startWorkflow(
request
)
console.log("Workflow id: {}", workflowId)
(def request {:name "<name of your workflow>"
:input {:amount: 100
:account: "account-id"}})
(def workflow-id workflow-resource/start-workflow [options, request])
(log/info "Workflow id:" workflow-id)
As an example, we might invoke this method when an endpoint is called, such as this API call in Java.
@PostMapping(value = "/triggerDepositFlow", produces = "application/json")
public ResponseEntity<Map<String, Object>> triggerDepositFlow(@RequestBody DepositDetail depositDetail) {
log.info("Starting deposit flow for: {}", depositDetail);
return ResponseEntity.ok(workflowService.startDepositWorkflow(depositDetail));
}
In addition to triggering from code, we can also run them from: