Connectors

Contact support

Making raw API calls

Making raw API calls

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 APIsInteracting 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 result

SOAP Webservice API call

Example on making an API call to a SOAP Webservice:

import requests, base64, xmltodict, json

url = "https://domain.com/api/SomeWebService.asmx"

# See the SOAP Webservice documentation for the correct SOAP envelope to use
xml = """<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetData xmlns="http://...">
      <param>xxx</param>
    </GetData>
  </soap:Body>
</soap:Envelope>
"""

headers = {
    "Content-Type": "text/xml; charset=utf-8",
    "SOAPAction": "https://domain.com/api/SomeAction",
    "Authorization": "Basic " + basic_auth # see below
}

result_xml = requests.post(url, data = xml, headers = headers).text
result_dict = xmltodict.parse(result_xml)
rows = result_dict["soap:Envelope"]["soap:Body"]["GetDataResponse"]["Result"]["Rows"]
st.write(rows)

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)