Connectors

Contact support

Publish APIs

In Peliqan you can define and publish API endpoints, in order to share data with partners, customers etc.

Publishing an API endpoint

In Peliqan, go to the Build section, and click the “+” icon when hovering over “API endpoints”:

image

Add a new endpoint and link it to a Python script of type “API handler”. See below on how to write a low-code Python script to handle the API requests.

image

Create a JWT web token under Settings > Security, and use this in the Authorization header to authenticate when consuming this API endpoint.

The full URL of your API endpoint is shown on the API endpoint detail screen, as you can see in the above screenshot.

Adding a Python script to handle API requests

In Peliqan, go to the Build section, and click the “+” icon when hovering over “Apps”. Add a script (app) of type “API endpoint handler”:

image

The new script will have some boilerplate example code, that shows how you can get the details of the incoming request (such as the body, headers, querystring etc.) and how you can send a response:

def handler():
	# Get request details:
	method = request.method
	url = request.url
	path = request.path
	query_string = request.query_string
	headers = dict(request.headers)
	data = request.data
	form = request.form
	get_data = request.get_data() # combines data, form & query_string based on Content-Type

	# Example reading a parameter from the querystring
	from urllib.parse import parse_qs
  query_string_dict = parse_qs(query_string.decode("utf-8"))
  if "param1" in query_string_dict:
	  param1 = query_string_dict['param1'][0]

	# Example data for response: read data from a table (pq = Peliqan module)
	dbconn = pq.dbconnect('dw_2')
	table_data = dbconn.fetch('dw_2', 'salesforce', 'accounts')
	
	# Send the API response (e.g. return the table contents)
	return table_data

	# Send a response with status code and headers
	return data, status_code, headers
	return "", 404, { "some_header": "some_value" }