Skip to main content

Task-Based Orchestration

Welcome to the next level of API mastery with Fiscus SDK. Here, we’ll walk you through how to orchestrate multiple tasks and build multi-step workflows seamlessly. If you've conquered single API calls, you're going to love what’s next!

Sending and Managing Multiple Tasks

You’re not limited to one API call at a time! With Fiscus, you can send multiple tasks in a single request. This is ideal for situations where you need to coordinate actions across different APIs.

Key Benefits:

  • Efficiency: Send multiple tasks in a single API call, reducing network overhead.
  • Automation: Automate complex processes that require multiple API calls.

Example: Sending Multiple Tasks Simultaneously

Here’s a basic example of sending two tasks at once: one to create a CRM contact and another to send an email.

  1. Define Tasks
    Create an array of tasks. Each task corresponds to an API call with its parameters.
tasks = [
{
'connector': 'CRMSystem',
'operation': 'create_contact',
'params': {'name': 'John Doe', 'email': 'john@example.com'}
},
{
'connector': 'Gmail',
'operation': 'send_email',
'params': {
'to': 'john@example.com',
'subject': 'Welcome, John!',
'body': 'Glad to have you on board.'
}
}
]
  1. Execute the Tasks
    Send the tasks to Fiscus for execution.
response = client.execute(tasks=tasks)
  1. Handle the Response
    The response will contain results for each task.
if response.success:
print('Tasks executed successfully!')
else:
print(f'Error: {response.error_message}')

 

Orchestrating Multi-Step Workflows

In real-world scenarios, API workflows often involve multiple steps that depend on each other. With Fiscus, you can chain tasks and even include conditions to control the flow.

Why Orchestrate Multi-Step Workflows?

  • Dynamic Logic: Set conditions that decide the next task based on the outcome of the previous one.
  • Efficiency: Automate complex, multi-step processes without needing manual intervention.

Example: Chaining Tasks with Conditional Logic

Let’s say you want to first create a user in your CRM, then send them a welcome email, but only if the user was created successfully.

  1. Define Tasks with Conditional Logic

    You can use the conditions parameter to ensure the next task only runs if the previous one succeeds.

tasks = [
{
'connector': 'CRMSystem',
'operation': 'create_contact',
'params': {'name': 'John Doe', 'email': 'john@example.com'},
'custom_logic': lambda response: response.success # Set flag based on success
},
{
'connector': 'Gmail',
'operation': 'send_email',
'params': {
'to': 'john@example.com',
'subject': 'Welcome, John!',
'body': 'Glad to have you on board.'
},
'conditions': {
'if': lambda ctx: ctx.get('create_contact', False) # Only send email if contact creation was successful
}
}
]
  1. Execute the Workflow

    Now run the workflow, and Fiscus will handle the orchestration, only proceeding to the email task if the contact creation succeeds.

response = client.execute(tasks=tasks)
  1. Check Workflow Outcome

    Fiscus will automatically check the conditions and execute the tasks accordingly.

if response.success:
print('Workflow completed successfully!')
else:
print(f'Error: {response.error_message}')

Pro Tips for Workflow Orchestration:

  • Callbacks: Use pre- and post-execution hooks to customize the behavior before and after each task.
  • Dynamic Data: You can pass data dynamically between tasks using the context.
  • Error Handling: Build in custom error-handling logic to retry failed tasks or skip them entirely.

With Fiscus, the power to automate and orchestrate complex workflows is at your fingertips! Enjoy the flexibility of chaining API calls and scaling your processes with ease.