Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass parameters to Airflow Experimental REST api when creating dag run

Tags:

airflow

Looks like Airflow has an experimental REST api that allow users to create dag runs with https POST request. This is awesome.

Is there a way to pass parameters via HTTP to the create dag run? Judging from the official docs, found here, it would seem the answer is "no" but I'm hoping I'm wrong.

like image 537
Peter Berg Avatar asked May 01 '18 18:05

Peter Berg


People also ask

How do you pass variables to Airflow DAG?

You can pass parameters from the CLI using --conf '{"key":"value"}' and then use it in the DAG file as "{{ dag_run. conf["key"] }}" in templated field.

How do you trigger a DAG run?

You can trigger a DAG manually from the Airflow UI, or by running an Airflow CLI command from gcloud . Trigger in response to events. The standard way to trigger a DAG in response to events is to use a sensor.


1 Answers

I had the same issue. "conf" value must be in string

curl -X POST \
    http://localhost:8080/api/experimental/dags/<DAG_ID>/dag_runs \
    -H 'Cache-Control: no-cache' \
    -H 'Content-Type: application/json' \
    -d '{"conf":"{\"key\":\"value\"}"}'
like image 89
harscoet Avatar answered Sep 21 '22 03:09

harscoet