Call Platform API

Introduction #

SmartPip is built on Apache Airflow and supports all Airflow REST API endpoints. Through SmartChart’s API service, you can more conveniently call task scheduling APIs for automated triggering, status queries, and more.

Prerequisites #

Step Description
1 Create a Python dataset in SmartChart
2 Import get_auth_hearder() for authentication
3 Call SmartPip API endpoints

Example: Trigger a DAG #

  • Create a Python dataset in SmartChart
  • Write the following code:
from etl.smartpip import get_auth_hearder
import requests
header = get_auth_hearder()
url = '{smartpip_url}/api/v1/dags/{dag_id}/dagRuns'
ds = requests.post(url=url, headers=header, json={"conf":{}}).json()
  • Check DAG status before triggering:
from etl.smartpip import get_auth_hearder
import requests
header = get_auth_hearder()
url = '{smartpip_url}/api/v1/dags/{dag_id}/dagRuns?limit=1&order_by=-execution_date'
ds = requests.get(url=url, headers=header).json()
status = ds['dag_runs'][0]['state']
if status != 'running':
    url = '{smartpip_url}/api/v1/dags/{dag_id}/dagRuns'
    ds = requests.post(url=url, headers=header, json={"conf":{}}).json()