{
  "$comment": "Build sheet for two Smartsheet Bridge workflows. Bridge has no workflow import format, so this file is a module-by-module specification to rebuild in the Bridge editor (see bridge/README.md). Values in angle brackets are data references you pick from the Run Log. No credentials belong in this file: the API key lives only in the Bridge Call API profile's secret header.",
  "version": 1,
  "sheet": {
    "name": "FXMacroData USD inflation",
    "key_column": "Key",
    "key_format": "<currency>:<indicator>:<YYYY-MM-DD>",
    "columns": [
      {"title": "Key", "type": "TEXT_NUMBER", "primary": true},
      {"title": "Date", "type": "DATE"},
      {"title": "Value", "type": "TEXT_NUMBER"},
      {"title": "Previous", "type": "TEXT_NUMBER"},
      {"title": "Change", "type": "TEXT_NUMBER"},
      {"title": "Released at (UTC)", "type": "TEXT_NUMBER"},
      {"title": "Currency", "type": "TEXT_NUMBER"},
      {"title": "Indicator", "type": "TEXT_NUMBER"}
    ],
    "create_with": "python sync/fxmd_smartsheet_sync.py indicator --currency usd --indicator inflation --workspace-id <workspace id>"
  },
  "call_api_profile": {
    "name": "FXMacroData",
    "base_url": "https://api.fxmacrodata.com",
    "headers": {"Accept": "application/json"},
    "secret_headers": {"X-API-Key": "<your FXMacroData API key; leave the profile without it for the free USD tier>"}
  },
  "workflows": [
    {
      "name": "FXMacroData scheduled refresh",
      "trigger": {
        "type": "Schedule",
        "cadence": "Hourly, or daily shortly after the release you track",
        "note": "Each run upserts the latest release. Backfill history once with the sync CLI."
      },
      "states": [
        {
          "name": "Fetch latest",
          "module": "Utilities > Call API > Make API Call",
          "fields": {
            "Profile": "FXMacroData",
            "Method": "GET",
            "Endpoint": "v1/announcements/usd/inflation",
            "Form parameters": {"fields": "compact", "limit": "1"},
            "Stop the workflow if the API returns an error": true
          },
          "outputs_used": {
            "date": "<Run Log: Fetch latest > data > 0 > date>",
            "val": "<Run Log: Fetch latest > data > 0 > val>",
            "previous_value": "<Run Log: Fetch latest > data > 0 > previous_value>",
            "change_from_previous": "<Run Log: Fetch latest > data > 0 > change_from_previous>",
            "announcement_datetime": "<Run Log: Fetch latest > data > 0 > announcement_datetime>"
          }
        },
        {
          "name": "Find row",
          "module": "Smartsheet > Search Sheet",
          "fields": {
            "Sheet": "FXMacroData USD inflation",
            "Row Filters": [{"column": "Key", "condition": "equals", "value": "usd:inflation:<date>"}]
          }
        },
        {
          "name": "Exists?",
          "module": "Junctions > Match",
          "fields": {"Value": "<Run Log: Find row > row count (or first row ID)>", "Match": "row found"},
          "paths": {"match": "Update existing", "no match": "Add new"}
        },
        {
          "name": "Update existing",
          "module": "Smartsheet > Update Row",
          "fields": {
            "Sheet": "FXMacroData USD inflation",
            "Row ID": "<Run Log: Find row > first row > id>",
            "Cells": {
              "Value": "<val>",
              "Previous": "<previous_value>",
              "Change": "<change_from_previous>"
            }
          }
        },
        {
          "name": "Add new",
          "module": "Smartsheet > Add Row",
          "fields": {
            "Sheet": "FXMacroData USD inflation",
            "Cells": {
              "Key": "usd:inflation:<date>",
              "Date": "<date>",
              "Value": "<val>",
              "Previous": "<previous_value>",
              "Change": "<change_from_previous>",
              "Released at (UTC)": "<announcement_datetime>",
              "Currency": "USD",
              "Indicator": "inflation"
            }
          }
        }
      ]
    },
    {
      "name": "FXMacroData release webhook",
      "trigger": {
        "type": "Utilities > Inbound Webhooks > Workflow Trigger",
        "note": "Copy the generated request URL into an FXMacroData webhook subscription with destination generic. Treat the URL as a secret."
      },
      "fxmacrodata_subscription": {
        "request": "POST https://api.fxmacrodata.com/v1/webhooks/subscriptions",
        "body": {
          "url": "<Bridge workflow trigger request URL>",
          "destination": "generic",
          "events": ["announcement"],
          "currencies": ["usd"],
          "indicators": ["inflation"],
          "description": "Smartsheet Bridge"
        }
      },
      "runtime_fields": {
        "currency": "{{runtime.data.currency}}",
        "indicator": "{{runtime.data.indicator}}",
        "date": "{{runtime.data.latest_announcement.date}}",
        "val": "{{runtime.data.latest_announcement.val}}",
        "announcement_datetime": "{{runtime.data.latest_announcement.announcement_datetime}}",
        "event_id": "{{runtime.data.event_id}}"
      },
      "states": [
        {
          "name": "Find row",
          "module": "Smartsheet > Search Sheet",
          "fields": {
            "Sheet": "FXMacroData USD inflation",
            "Row Filters": [{"column": "Key", "condition": "equals",
                             "value": "{{runtime.data.currency}}:{{runtime.data.indicator}}:{{runtime.data.latest_announcement.date}}"}]
          }
        },
        {
          "name": "Exists?",
          "module": "Junctions > Match",
          "paths": {"match": "Update existing", "no match": "Add new"}
        },
        {
          "name": "Update existing",
          "module": "Smartsheet > Update Row",
          "fields": {"Cells": {"Value": "{{runtime.data.latest_announcement.val}}"}}
        },
        {
          "name": "Add new",
          "module": "Smartsheet > Add Row",
          "fields": {
            "Cells": {
              "Key": "{{runtime.data.currency}}:{{runtime.data.indicator}}:{{runtime.data.latest_announcement.date}}",
              "Date": "{{runtime.data.latest_announcement.date}}",
              "Value": "{{runtime.data.latest_announcement.val}}",
              "Released at (UTC)": "{{runtime.data.latest_announcement.announcement_datetime}}",
              "Currency": "{{runtime.data.currency}}",
              "Indicator": "{{runtime.data.indicator}}"
            }
          }
        }
      ]
    }
  ]
}
