Can parameters be passed to Model Schedule via the API?
We have a number of data model schedules that are launched via API calls. Is it possible to pass parameters to the model processing through the schedule? For example, I have a model that runs a bunch of processes on our data based on a variable called RunDate that indicates the date range to pull the data for. Can the schedule pass the RunDate into the model process via the schedule? I know dashboards and reports can use parameters but can model processes?
Thanks!
3 replies
-
Hi , the model parameters can be set using the UpdateVariableValue API
-
Hi Jason,
Yes. Look up the model's ID, read its variables with getMasterFlowVariables, then set them with updateVariableValue. All calls need an enterprise admin token.
Which ID to use depends on what the schedule is attached to:
- Schedule on a materialized (deployed) model: use the modelId returned by dataSources/findModelConnection. This is the materialized model's ID, and the run takes its definition from there.
- Schedule on a CMS model item: use the item's id from content/findContentItem. The run takes its definition from that item.If you use the wrong one, you will update a definition the schedule never reads.
var pyramidURL = "http://mysite.com/api3/";
// step 1: authenticate (the response is the token as plain text)
let token = callApi("authentication/authenticateUser", {
"username": "adminUser",
"password": "abc123!"
}, "", false);// step 2: find the model (materialized case) - modelId is the materialized model's system ID
let model = callApi("dataSources/findModelConnection", {
"serverSearchCriteria": { "searchValue": "Pyramid IMDB" },
"databaseSearchCriteria": { "searchValue": "PyramidDemo" },
"modelSearchCriteria": { "searchValue": "PyramidDemo" }
}, token);
let itemId = model[0].modelId;// step 3: read the variables (name, variableCurrentValue, variableDataType, variableType)
let vars = callApi("dataSources/getMasterFlowVariables", itemId, token);// step 4: set the value
let res = callApi("dataSources/updateVariableValue", {
"variableValueList": [
{ "itemId": itemId, "variableName": "RunDate", "variableValue": "2025-03-31" }
]
}, token);
// check res.results[i].success / errorMessage// ##### generic REST API calling method ##############
function callApi(path, data, token = "", parseResult = true) {
var xhttp = new XMLHttpRequest();
xhttp.open("POST", pyramidURL + path, false);
xhttp.setRequestHeader("paToken", token);
xhttp.send(JSON.stringify(data));
return parseResult ? JSON.parse(xhttp.responseText) : xhttp.responseText;
}Value formats (variableValue is always a string):
- Date: yyyy-MM-dd
- DateTime: yyyy-MM-dd HH:mm:ss
- List variable: a JSON array encoded as a string, "[\"2025-01-01\",\"2025-02-01\"]"
- Only internal variables can be set. Query variables are not affected.Check the result: a value that doesn't match the variable's type still returns HTTP 200. That variable's entry in results has success: false and an errorMessage.
Putting it together: call updateVariableValue with the new RunDate just before the schedule runs, for example as the first step of the script that triggers it.