Executing API Tasks and Orchestration
Let’s dive into the core functionality of Fiscus SDK — executing API tasks! Whether you need a single API call or a more complex series of actions, this is where Fiscus shines. 🚀
Basic Execution with FiscusClient
The FiscusClient is your main tool for interacting with APIs via the Fiscus platform. Here’s how you use it to execute tasks and orchestrate workflows.
Overview of the execute Method
The execute method is the heart of Fiscus SDK. It's your go-to method for:
- Executing a Single API Call: Need to send an email, create a record, or get data?
executeis your one-stop shop. - Task-Based Execution: You can send multiple tasks or chained events using the same method.
- Handling Responses: The method returns a
FiscusResponseobject, making it easy to handle results.
Here’s a breakdown of how the execute method works:
-
Parameters:
connector_name: The name of the service (e.g., Gmail, QuickBooks).operation: The specific API operation (e.g.,send_email,create_invoice).params: A dictionary of the parameters required for the API call.user(optional): If you’re using a stateful backend, you can pass aFiscusUserobject.callbacks(optional): You can define custom success or error callbacks.
-
Returns:
- A
FiscusResponseobject containing the result of the API call.
- A
Executing Single API Calls
Now, let's look at how to execute simple API calls with FiscusClient.
- Python
Example: Sending an Email
- Initialize the Client
Start by creating aFiscusClientinstance.
client = FiscusClient(api_key='YOUR_FISCUS_API_KEY')
- Prepare Your Parameters
Define the parameters for the API call. In this case, let’s send an email using the Gmail connector.
email_params = {
'to': 'recipient@example.com',
'subject': 'Welcome to Fiscus',
'body': 'This email was sent using Fiscus SDK!'
}
- Execute the Call
Use theexecutemethod to perform the operation.
response = client.execute('Gmail', 'send_email', email_params)
- Handle the Response
Check the success of the operation by inspecting theFiscusResponseobject.
if response.success:
print('Email sent successfully!')
else:
print(f'Error: {response.error_message}')
Example: Creating an Invoice
Here’s another example where we’ll create an invoice using the QuickBooks connector.
- Initialize the Client
client = FiscusClient(api_key='YOUR_FISCUS_API_KEY')
- Prepare Invoice Parameters
invoice_params = {
'customer_id': '12345',
'amount': 250.00,
'due_date': '2024-12-01'
}
- Execute the Call
response = client.execute('QuickBooks', 'create_invoice', invoice_params)
- Handle the Response
if response.success:
print(f"Invoice created: {response.result}")
else:
print(f"Error: {response.error_message}")
Key Takeaways for Single API Calls
- Simple Setup: With
FiscusClientand theexecutemethod, sending a single API call is quick and painless. - Response Handling: Every call returns a
FiscusResponse, giving you immediate access to the result or any error messages. - Real-Time Execution: This method is synchronous, so it’ll wait for the result before continuing, making it ideal for one-off tasks.
Now that you’ve mastered single API calls, you’re ready to move onto more advanced orchestration and multi-task workflows! 🌟