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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With