How to Trigger Airflow DAG Using REST API

Obinna Onyema
Towards Data Engineering
2 min readNov 10, 2023

--

Not a Medium member? Click here to read for free.

Sometimes you want to programmatically trigger an airflow DAG. Airflow allows you to enable this functionality when needed. In this article, I will do a simple demo.

1. Enable REST API in Airflow

In the config, enable authentication and set it to basic authentication. I have version 3.8 of the docker-compose document and version 2.6.2 of airflow. In my docker-compose.yaml file, basic authentication is already set. Set your api config parameter auth_backends to airflow.api.auth.backend.basic_auth.

2. Build your POST request

I’m using Postman in this demo for the API requests. Define headers as follows:

API headers

Note that for basic authentication you need to encode username and password to base64 which is why the value of authorization key in the headers is fill in that way. I used a free online tool at base64encode.org to generate the encoding for these demo credentials. The format for username and password should be “username:password”:

--

--