Run scheduled saved import tutorial
In this tutorial, you will use the Varicent Incentives REST APIs to run a scheduled saved import that will upload data to your model.
Prerequisites
On the Varicent server, you have saved the file that contains the data that you want to import. For more information on creating saved import files, see Managing Saved Imports.
In Scheduler, you have created a task to run the saved import file, which uploads the data in the file to your model. For more information on creating tasks in Scheduler, see Scheduler Module.
You have obtained your Varicent API Key as outlined in REST API authentication and headers.
Overview
In this tutorial, we will be using the following two REST API calls to run the saved import:
- Get schedule items
This call gets the ID of the Scheduler task that runs the saved import file.
- Run schedule item
This call uses the ID obtained by the
Get schedule items
call to run the Scheduler task that uploads the data in the saved import file.
We will then use the following REST API calls to see if the task was completed successfully:
- GET live activities
This call is used to see if the task is still running.
- Get scheduled item
This call is used to check the status of the last task run.
- Get audit scheduler
This call is used to view Scheduler log information if the task encountered an error.
Retrieving the task ID
First, use the Varicent Incentives REST API call that retrieves a list of all the Scheduler tasks and subtasks.
Make the following request:
GET /api/v1/scheduleitem
For example,
curl -X GET -H "Authorization: Bearer API_KEY" -H "Model: YOUR_CLIENT_MODEL” -H "Content-Type: application/json" https://YOUR_ICM10_API_SERVER_ADDRESS/api/v1/scheduleitem
In the response body, find the Scheduler task that was created to run the saved import, and note the ID.
{ "id": 12, "name": "CompPlanApproval Import", "scheduleItemType": "Import", "order": 7, "lastRun": "2012-09-06T05:01:09.473Z", "lastRunStatus": "Success", "activation": "Enabled", "nextRun": "0001-01-01T00:00:00", "parent": 1, "settings": { "schedulerSettingsId": 0, "scheduleItemId": 12, "emailOnFailure": false, "emailOnSuccess": false, "stopOnFailure": false, "stopToolOnTimeout": false, "isGlobal": false, "overrideChildSettings": false, "successEmails": [], "failEmails": [], "externalToolTimeout": 0, "enableRetries": false, "version": { "rowVersion": 1801131 }
Running the Scheduler task
Next, use the ID obtained from the Get scheduler items
call to run the saved import task in Varicent Incentives .
Make the following request:
POST /api/v1/rpc/scheduleitem/{id}/run
For example,
curl -X POST -H "Authorization: Bearer API_KEY" -H "Model: YOUR_CLIENT_MODEL” -H "Content-Type: application/json" https://YOUR_ICM10_API_SERVER_ADDRESS/api/v1/rpc/scheduleitem/12/run
In the request response, note the returned
ProgressId
. In this example, theProgressID
is 15850.{ "completedactivities": "api/v1/completedactivities/15850", "liveactivities": "api/v1/liveactivities/15850" }
Checking the Scheduler task run status
Finally, you can run several calls to check on the status of the Scheduler task, and get Scheduler log information if you encounter an error.
You can make the following request to see if the task is running:
GET /api/v1/liveactivities/{ProgressId}
Note
You should have obtained the
ProgessId
from Step 2 of Running the Scheduler task.For example,
curl -X GET -H "Authorization: Bearer API_KEY" -H "Model: YOUR_CLIENT_MODEL” -H "Content-Type: application/json" https://YOUR_ICM10_API_SERVER_ADDRESS/api/v1/liveactivities/15850
The response returns a
status
ofRunning
if the task is still running. If the task has completed, the response returns a message indicating the task was not found.You can make the following request to see if the task completed successfully or encountered an error:
GET api/v1/scheduleitem/{ProgressId}
Note
You should have obtained the
ID
in Retrieving the task ID.For example,
curl -X GET -H "Authorization: Bearer API_KEY" -H "Model: YOUR_CLIENT_MODEL” -H "Content-Type: application/json" https:// YOUR_ICM10_API_SERVER_ADDRESS/api/v1/scheduleitem/12
The response returns a
lastRunStatus
ofSuccess
if the task completed successfully. If the task encounters an error, the response will return alastRunStatus
ofError
.If the task encountered an error, you can make the following request to view the Scheduler log details:
GET api/v1/auditschedulers?offset=0&limit=1
Note
The
offset
and limit parameters ensure that only the last Scheduler log entry is returned.For example,
curl -X GET -H "Authorization: Bearer API_KEY" -H "Model: YOUR_CLIENT_MODEL” -H "Content-Type: application/json" https:// YOUR_ICM10_API_SERVER_ADDRESS/api/v1/auditschedulers?offset=0&limit=1
The response returns the error message details.