Below you will find examples on how to make “raw” API calls from your Python scripts in Peliqan.
Note: Peliqan provides SaaS API wrapper functions for a wide range of SaaS applications (CRM, ERP, accounting, messaging etc). For these connectors, you do not need to make “raw” API calls. More info:Interacting with SaaS APIs
Comparison between both methods:
Peliqan SaaS API wrapper functions | Raw API calls |
Authentication is automatically handled | You have to handle authentication in your script |
Headers, body, querystring etc. are automatically built | You have to build up the API request: method (GET, POST…), URL, querystring, headers, body |
REST API call
Example on making API calls to a REST API:
import requests
# Get data
url = "https://domain.com/api/companies"
result = requests.get(url)
st.write(results) # show result
# Post data
headers = {
"Authorization": "Bearer " + token
}
data = {
"key": "value"
}
result = requests.post(url, json = data, headers = headers)
st.write(results) # show resultSOAP Webservice API call
Example on making an API call to a SOAP Webservice:
Authentication
Example of using Basic Authentication:
login = 'xxx'
pw = 'xxx'
basic_auth = base64.b64encode((login + ":" + pw).encode("ascii")) .decode("ascii")
headers = {
"Authorization": "Basic " + basic_auth
}
result = requests.get(url, headers = headers)Example of using a JWT or token:
headers = {
"Authorization": "Bearer " + token
}
result = requests.get(url, headers = headers)