Forum Discussion
DAGRun via API
Hi,
I am trying to find out how to run Airflow DAG via API call.
When I called an API from swagger UI page, it works properly. (using /connection api as example for simplicity)
However, if I called the same API from shell script or postman, it will always redirect me to microsoft login page.
Is there a way to authenticate using shell script or do I need to change airflow Configuration Overrides to allow basic authentication (if possible)?
Is it currently possible to run a DAG from a REST API call using basic authen or is there a way to authenticate using shell script ?
3 Replies
- AnonymousNot applicable
Hi saritboo
Modify the 'airflow.cfg' file to enable basic authentication. You need to set the 'auth_backend' to 'airflow.api.auth.backend.basic_auth'. This allows you to use basic authentication for API calls.
[api] auth_backend = airflow.api.auth.backend.basic_authEnsure you have a user created in Airflow with the necessary permissions to trigger DAGs.
When making API calls from a shell script or Postman, include the 'Authorization' header with the base64 encoded username and password. Here’s an example using 'curl'
curl -X POST "http://your-airflow-url/api/v1/dags/your_dag_id/dagRuns" \ -H "Authorization: Basic $(echo -n 'username:password' | base64)" \ -H "Content-Type: application/json" \ -d '{"conf": {"key": "value"}}'By following these steps, you should be able to authenticate and run Airflow DAGs via API calls without being redirected to the Microsoft login page
Here's the link for your reference:
API Authentication — apache-airflow-providers-fab Documentation
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - saritbooFrequent Visitor
Hi Anonymous
It seems like that AIRFLOWAPIAUTH_BACKEND is default to airflow.api.auth.backend.basic_auth (assuming if it is the same config as auth_backend)
I also tried to modify configuration overrides with
AIRFLOW__API__AUTH_BACKENDS : airflow.api.auth.backend.basic_auth
but it doesn't seems to work, I am not sure if I am doing it right.
I cannot find any document related to API setting for Fabric Airflow. Hope for more tutorial on this soon.
reference:
https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#auth-backends
- Prince0011Solution Sage
Hi User,
The behavior you're seeing is expected. The Swagger UI is already authenticated through your Microsoft Fabric session, whereas requests from Postman or a shell script don't have that authentication context, so they're redirected to the Microsoft Entra ID (Azure AD) sign-in page.
A few things to check:
Verify whether the Airflow REST API in Fabric supports Microsoft Entra ID (OAuth 2.0) authentication for external clients. If so, you'll need to acquire an access token and include it in the Authorization: Bearer <token> header.
Basic Authentication is generally not supported for Microsoft Fabric services, so enabling it may not be possible.
If you're calling the API from automation (Postman, curl, or a script), consider using a service principal or another supported Microsoft Entra authentication flow, if the API supports it.
If the API documentation doesn't describe external authentication, it may currently be limited to authenticated Fabric sessions or have preview limitations.
For more information:
Apache Airflow in Microsoft Fabric: https://learn.microsoft.com/fabric/data-factory/apache-airflow-jobs-hello-world
Microsoft Fabric REST API: https://learn.microsoft.com/rest/api/fabric/
Microsoft identity platform (OAuth 2.0): https://learn.microsoft.com/entra/identity-platform/
Could you also clarify:
Which Airflow REST endpoint are you trying to call (for example, POST /dags/{dag_id}/dagRuns)?
Are you using Microsoft Entra user authentication or a service principal?
Is your goal to trigger DAGs from an external application or from another Fabric pipeline?
This will help determine the most appropriate authentication approach for your scenario.
💡 Helpful? Give a Kudos 👍 — keep the community growing.
✅ Solved your issue? Mark this as the Accepted Solution ✔️
Best regards,
Prince Singh | Data Science & Microsoft Fabric Enthusiast