Hitting the Airflow API running on Astronomer cloud

379 Views Asked by At

We currently have airflow DAGs running on an Astronomer cloud instance, and we’re trying to develop external functions that would eventually trigger these DAGs.

Referencing the documentation for this → Make Requests to the Airflow REST API | Astronomer Documentation

Making a call to the API would mean sending an HTTP request to: https://[AIRFLOW-DOMAIN]/api/v1/[method to call] [AIRFLOW-DOMAIN]: Use https://[your-base-domain]/[deployment-release-name]

i.e. https://gcpXXXY.us-east4.astronomer.io/gravitational-flux-XXXX/api/v1/pools

Not sure if it was necessary, but also set an environment variable AIRFLOW__API__AUTH_BACKEND = airflow.api.auth.backend.default

The issue is, instead of getting 200 or 401 or 403 responses, we’d always get some HTML like below when testing out API calls via the Postman app. When checking the HTML in the browser, it's basically a 404 Page see screenshot

What am I missing? Thanks in advance!

<!DOCTYPE html>
<html>
<head>
<meta name=“robots” content=“noindex”>
<!-- Environment variables injected from NGINX —>
.
.
.
<meta http-equiv=“X-UA-Compatible” content=“IE=edge” />
<meta charset=“utf-8”>
<title>Astronomer
.
.
</head>
<body>
<div id=“root”>
<script src="/assets/runtime.82af4b31.js">
<script src="/assets/2.36213ffe.js">
<script src="/assets/index.b05feb43.js">
</body>
</html>
1

There are 1 best solutions below

0
On

You need to retrieve an access token first.

curl --location --request POST "https://auth.astronomer.io/oauth/token" \
        --header "content-type: application/json" \
        --data-raw '{
            "client_id": "<api-key-id>",
            "client_secret": "<api-key-secret>",
            "audience": "astronomer-ee",
            "grant_type": "client_credentials"}'

You can then use that token (24 hour expiry) and call the Airflow API on your Astronomer instance.

curl -X GET <your-deployment-url>/api/v1/dags \
   -H 'Cache-Control: no-cache' \
   -H 'Authorization: Bearer <your-access-token>'

More information can be found here: https://docs.astronomer.io/astro/airflow-api