How to pass the dynamic date in the body section of http input in the Watcher config

The below is my watcher config and I want to pass the dynamic date in the body part so that it can take the current date in MM-dd-yyyy format to call the REST aPI endpoint:

{
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  },
  "input": {
    "http": {
      "request": {
        "scheme": "https",
        "host": "volume-prediction-restapi-feature-q700-tenant--40ec161272e5e2a0.apps.ocp-sai-s1.saifg.rbc.com",
        "port": 443,
        "method": "post",
        "path": "/q700/inference",
        "params": {},
        "headers": {
          "Content-Type": "application/json"
        },
        "body": """
        {
          "date": "{{ctx.payload.formatted_date}}"
        }
        """
      }
    }
  },
  "condition": {
    "always": {}
  },
  "actions": {
    "send_email": {
      "email": {
        "account": "exchange_account",
        "profile": "standard",
        "to": [
          "abc@xyz.com"
        ],
        "subject": "Daily API Predictions Response",
        "body": {
          "text": "Watcher executed. API returned: {{#toJson}}ctx.payload{{/toJson}}"
        }
      }
    },
    "log": {
      "logging": {
        "level": "info",
        "text": "HTTP request sent with formatted date: {{ctx.payload.formatted_date}}"
      }
    }
  },
  "transform": {
    "script": {
      "source": """
      return ['formatted_date': ctx.execution_time.format('yyyy-MM-dd')];
      """,
      "lang": "painless"
    }
  }
}

I tried everything to parse the date but no luck coz in the watcher logs, the date is showing empty and not populating. Can someone pls help on this ?

Hello @Ria_Shah

We can try below using chain input :

{
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  },
  "input": {
    "chain": {
      "inputs": [
        {
          "date_input": {
            "transform": {
              "script": {
                "source": """
                  def formatter = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd");
                  def formatted = formatter.format(ctx.execution_time);
                  return ['formatted_date': formatted];
                """,
                "lang": "painless"
              }
            }
          }
        },
        {
          "http_input": {
            "http": {
              "request": {
                "scheme": "https",
                "host": "volume-prediction-restapi-feature-q700-tenant--40ec161272e5e2a0.apps.ocp-sai-s1.saifg.rbc.com",
                "port": 443,
                "method": "post",
                "path": "/q700/inference",
                "headers": {
                  "Content-Type": "application/json"
                },
                "body": """
                {
                  "date": "{{ctx.payload.formatted_date}}"
                }
                """
              }
            }
          }
        }
      ]
    }
  },
  "condition": {
    "always": {}
  },
  "actions": {
    "send_email": {
      "email": {
        "account": "exchange_account",
        "profile": "standard",
        "to": [
          "abc@com"
        ],
        "subject": "Daily API Predictions Response",
        "body": {
          "text": "Watcher executed. API returned: {{#toJson}}ctx.payload{{/toJson}}"
        }
      }
    },
    "log": {
      "logging": {
        "level": "info",
        "text": "HTTP request sent with formatted date: {{ctx.payload.formatted_date}}"
      }
    }
  }
}

Thanks!!