Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull xCom in HttpSensor operator

Tags:

airflow

I want to call an API, which needs data of the previous task which I saved in xCom.How to access that xCom.

I am using HttpOperater as well as HttpSensor for calling API.

like image 672
P S Nirmal Avatar asked Jul 26 '26 15:07

P S Nirmal


1 Answers

you need to use the xcom_pull method on the context:

http_task = SimpleHttpOperator(
    task_id='http_call',
    endpoint='nodes/url',
    data="name=Joe",
    headers={"Content-Type": "application/x-www-form-urlencoded"},
    dag=dag,
)

def get_http_payload(**context):
    http_payload = ['ti'].xcom_pull(task_ids='http_call')
    print(http_payload)

process_output = PythonOperator(
    task_id='process_stuff',
    python_callable=get_http_payload,
    provide_context=True,
    dag=dag,
)

http_task >> process_output
like image 62
Breathe Avatar answered Jul 30 '26 09:07

Breathe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!