capabilities.work

Upsert a Variable

A 4-step recipe with Apache Airflow. We can help you get access.

Recipe · 4 steps

Upsert a Variable

Create or update an Airflow variable by key.

  1. Look the variable up by key. A 200 means it exists and should be patched; a 404 means it must be created. Both outcomes are expected, so both are treated as success and the branch is decided on the status code.
  2. Patch the existing variable. The update_mask restricts the write to the value and description fields, and the key in the body must match the key in the path.
  3. Create the variable when the lookup found nothing under this key.
  4. Read the variable back and require the stored value to match what was sent, closing the loop on either branch.
What you'll need to have ready
  • variableKey: The variable key to upsert (e.g. "warehouse_conn_target").
  • value: The variable value. Airflow stores variable values as strings; JSON payloads should be serialized by the caller.
  • description: A human readable description stored alongside the variable.
For your developer

Arazzo workflow apache-airflow:upsert-variable, 4 operations: getApiV2VariablesByVariableKey → patchApiV2VariablesByVariableKey → post_variables → getApiV2VariablesByVariableKey. Specs on APIs.io.