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).
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')
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: Data sync & Reverse ETL
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:
Odoo = pq.connect("Odoo") # use your name of the connection
result = Odoo.update("product", id = 1, name = "New product name")
st.text("Result: %s" % result)
Odoo.add("product", name="My product", price=100.05)
Odoo.update("invoice", id=123, payment_state = "in_payment", note = "...")
Odoo.delete("product", id=456)
pq.refresh_connection(connection_name = "Odoo") # see below
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:
Making raw API calls