Updates to the Airflow REST API are released in new Airflow versions and new releases don’t have a separate release cycle or versioning scheme. To take advantage of specific Airflow REST API functionality, you might need to upgrade Astro Runtime. See Upgrade Runtime and the Airflow release notes.
Airflow REST API v2 (Airflow 3.0+)The Airflow REST API is available at
/api/v2 for Airflow 3.0 and above. Some endpoints and parameters have changed. See the Airflow API documentation for more information.Prerequisites
- A Deployment on Astro.
- A Deployment API token, Workspace API token, or an Organization API token.
- cURL or, if using Python, the Requests library.
- The Astro CLI.
Step 1: Retrieve your access token
- Workspace token
- Organization token
- Deployment API token
Follow the steps in Create a Workspace API token to create your token. Make sure to save the token on creation in order to use it later in this setup.
Step 2: Retrieve the Deployment URL
Your Deployment URL is the host you use to call the Airflow API.-
Run the following command to retrieve the URL for your Deployment Airflow UI:
/home. For example, if the home page of your Deployment Airflow UI is hosted at clq52c95r000208i8c7wahwxt.astronomer.run/dz3uu847/home, your Deployment URL is clq52c95r000208i8c7wahwxt.astronomer.run/dz3uu847.
Step 3: Make an Airflow API request
You can execute requests against any endpoint that is listed in the Airflow REST API reference. To make a request based on Airflow documentation, make sure to:- Use the Astro access token from Step 1 for authentication.
- Replace
airflow.apache.orgwith your Deployment URL from Step 1.
The Airflow REST API doesn’t have rate-limiting.
Example API Requests
The following are common examples of Airflow REST API requests that you can run against a Deployment on Astro.List Dags
To retrieve a list of all Dags in a Deployment, you can run aGET request to the dags endpoint
cURL
Python
Trigger a Dag run
You can trigger a Dag run by executing aPOST request to Airflow’s dagRuns endpoint.
This will trigger a Dag run for the Dag you specify, which is equivalent to clicking the Play button in the main Dags view of the Airflow UI. The request body must include the logical_date key — it can be null, which runs the Dag immediately, but it can’t be omitted. An empty body {} returns a 422 Unprocessable Entity error.
cURL
Python
Trigger a Dag run by date
You can also specify alogical_date at the time in which you wish to trigger the Dag run by passing the logical_date with the desired timestamp with the request’s data field. The timestamp string is expressed in UTC and must be specified in the format "YYYY-MM-DDTHH:MM:SSZ", where:
YYYYrepresents the year.MMrepresents the month.DDrepresents the day.HHrepresents the hour.MMrepresents the minute.SSrepresents the second.Zstands for “Zulu” time, which represents UTC.
cURL
Python
Using Python:Pause a Dag
You can pause a Dag by executing aPATCH command against the dag endpoint.
Replace <your-dag-id> with your own value.
cURL
Python
Trigger Dag runs across Deployments
You can use the Airflow REST API to make a request in one Deployment that triggers a Dag run in a different Deployment. This is sometimes necessary when you have interdependent workflows across multiple Deployments. On Astro, you can do this for any Deployment in any Workspace or cluster. This topic has guidelines on how to trigger a Dag run, but you can modify the example Dag provided to trigger any request that’s supported in the Airflow REST API.- Create a Deployment API token for the Deployment that contains the Dag you want to trigger.
-
In the Deployment that contains the triggering Dag, create an Airflow HTTP connection with the following values:
-
Connection Id:
http_conn - Connection Type: HTTP
-
Host:
<your-deployment-url> -
Schema:
https -
Extra:
See Manage connections in Apache Airflow.
-
Connection Id:
If the
HTTP connection type is not available, double check that the HTTP provider is installed in your Airflow environment. If it’s not, add apache-airflow-providers-http to the requirements.txt file of our Astro project and redeploy it to Astro.-
In your triggering Dag, add the following task. It uses the
HttpOperatorto make a request to thedagRunsendpoint of the Deployment that contains the Dag to trigger.