For Deployments on Astro, you can use the Airflow REST API to automate Airflow workflows. For example, you can externally trigger a dag run without accessing your Deployment directly by making an HTTP request in Python or cURL to the dagRuns endpoint in the Airflow REST API. To test Airflow API calls in a local Airflow environment running with the Astro CLI, see Troubleshoot your local Airflow environment.Documentation Index
Fetch the complete documentation index at: https://astronomer-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
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. SeeUpgrade Runtimeand theAirflow 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 does not 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 with a logical_date value of NOW(), which is equivalent to clicking the Play button in the main Dags view of the Airflow UI.
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
HTTPconnection type is not available, double check that theHTTP provideris installed in your Airflow environment. If it’s not, addapache-airflow-providers-httpto therequirements.txtfile of our Astro project and redeploy it to Astro.-
In your triggering dag, add the following task. It uses the HttpOperator to make a request to the
dagRunsendpoint of the Deployment that contains the dag to trigger.