The Peliqan low-code Python environment provides single line functions to interact with APIs from connected SaaS applications. These functions abstract away the complexities of working with a specific API (authentication, error handling etc).
These writeback functions (for example “CRM Update contact” or “Accounting Create Invoice”) are the fundamentals for data syncs and Reverse ETL.
Here’s an example to write a contact to Hubspot (CRM):
hubspot_api.add('contact', {"email": "john@acme.com", "name": "John Doe"})And here’s an example to send a message to Slack:
slack_api.add('message', channel = 'QA', text = 'Data quality alert')Retries & Timeouts
Every writeback function will automatically do retries, e.g. when the API responds with a 429 Rate Limit response code. Retries will be executed with a pause in between. This means that one insert or update could take multiple minutes to complete if rate limiting occurs.
Peliqan will wait for a maximum of 120 seconds for one individual API call to complete. If an API does not respond within 120 seconds, Peliqan will retry (if timeout=False) or throw a Timeout error (if timeout=True).
Add the optional parameter timeout=True to lower the amount of retries, which will reduce the maximum execution time of one writeback function to complete.
timeout=False:
- Retries on 429 rate limit: 8 retries up to 30 minutes
- Retries on Timeout (120 seconds max per API call): 5 retries up to 50 seconds
- Retries on Connection error & Chunk encoding error: 2 retries up to 60 seconds
timeout=True:
- Retries on 429 rate limit: 2 retries up to 30 seconds
- No retry on Timeout (120 seconds max per API call)
- No retry on Connection error & Chunk encoding error
Use cases: data activation
The Peliqan SaaS API wrapper functions can be used for various use cases. We refer to these use cases as “Data Activation”. Here are a few examples:
- Send alerts to Slack
- Send an email with a report attached
- Write data to a Google Sheet
- Add a contact to a CRM such as Hubspot or Salesforce
- Create an invoice in an accounting system
- Import a CSV file
- Writebacks from the data warehouse to SaaS applications
- Data syncs (Reverse ETL, custom data pipelines, custom data exports etc.). More info: Custom data syncs
Connecting a SaaS API
First, add a connection in Peliqan under My Connections, for example Hubspot. Note that a SaaS connection in Peliqan is used for 2 things:
- READ: Sync data from the source (e.g. Hubspot) into the data warehouse
- WRITE: Enable interactions with the SaaS API: e.g. adding data into Hubspot
Next, click on “Build” in the left navigation bar, and add a “data app” (Python script). Expand “Connected SaaS APIs” in the right pane and click on the function that you want to use, for example “Add contact” for Hubspot. The code snippet will be inserted into your script:
Note that the actual insert of a new contact in Hubspot is only one line of code:
hubspot_api.add('contact', {"email": "john@acme.com", "name": "John Doe"})You can now run your script (click on “Save & Run”) and the contact will be added to Hubspot.
Write updates to a SaaS connection: add, update, delete records
Here’s an example using to add, update and delete records (invoices, products etc.) in the ERP system Odoo:
Refresh data in the data warehouse after writeback
After doing updates in a SaaS platform (e.g. Hubspot), you typically want to refresh the data in the Peliqan data warehouse, in order to see the updated data. This is a great way to verify that the data was added or updated successfully in the SaaS platform.
Examples to trigger a sync of the SaaS platform into the data warehouse:
pq.refresh_connection(connection_name = "Odoo", is_async = False)
pq.refresh_connection(connection_id = 789)is_async is an optional parameter:
is_async = True(Default): do not wait for refresh to completeis_async = False: wait for refresh to complete
Looping over rows and writing to a SaaS API
Example looping over rows of a table in Peliqan and using this to update records in Odoo:
dbconn = pq.dbconnect(pq.DW_NAME)
rows = dbconn.fetch(pq.DW_NAME, 'schema_name', 'table_name')
for row in rows:
Odoo.update("product", id = row["id"], name = row["name"])Troubleshooting
Making raw API calls
If you want to work with an API for which Peliqan does not provide a connector, you can make “raw” API calls. More info: