Member-only story

How to Trigger Airflow DAG Using REST API

Obinna Onyema
Towards Data Engineering
3 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”:

--

--

Towards Data Engineering
Towards Data Engineering

Published in Towards Data Engineering

Dive into data engineering with top Medium articles on big data, cloud, automation, and DevOps. Follow us for curated insights and contribute your expertise. Join our thriving community of professionals and enthusiasts shaping the future of data-driven solutions.

Obinna Onyema
Obinna Onyema

Written by Obinna Onyema

Enjoying building solutions with data and AI. Machine Learning Researcher https://www.linkedin.com/in/obinna-onyema/

Responses (1)

Write a response