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 ?