Tasks API
This set of endpoints allows us to interact with tasks that have been created in the Nexus Repository. You will need appropriate privileges to view, create, update, or delete tasks.
For detailed configuration settings see the Tasks documentation.
List Tasks
This endpoint iterate through a listing of all the existing tasks.
GET /service/rest/v1/tasks
curl 'http://localhost:8081/service/rest/v1/tasks' \ -u admin:admin123 \ -H 'accept: application/json'
Include the type of tasks filter the results.
curl 'http://localhost:8081/service/rest/v1/tasks?type=assetBlob.cleanup' \ -u admin:admin123 \ -H 'accept: application/json'
{ "items" : [ { "id" : "3f0173a8-c379-44c3-8ba3-2f0d0290bbfa", "name" : "Rebuild all browse trees", "type" : "create.browse.nodes", "message" : null, "currentState" : "WAITING", "lastRunResult" : null, "nextRun" : null, "lastRun" : null }, { "id" : "0261aed9-9f29-447b-8794-f21693b1f9ac", "name" : "Hello World", "type" : "script", "message" : null, "currentState" : "WAITING", "lastRunResult" : null, "nextRun" : null, "lastRun" : null } ], "continuationToken" : null }
Get Task by Identifier
This endpoint retrieves the details on an individual task.
GET /service/rest/v1/tasks/{id}
curl 'http://localhost:8081/service/rest/v1/tasks/0261aed9-9f29-447b-8794-f21693b1f9ac' \ -u admin:admin123 \ -H 'accept: application/json'
{ "id" : "0261aed9-9f29-447b-8794-f21693b1f9ac", "name" : "Hello World", "type" : "script", "message" : null, "currentState" : "WAITING", "lastRunResult" : null, "nextRun" : null, "lastRun" : null }
Run Task
This endpoint runs an individual task.
POST /service/rest/v1/tasks/{id}/run
curl -u admin:admin123 -X POST 'http://localhost:8081/service/rest/v1/tasks/0261aed9-9f29-447b-8794-f21693b1f9ac/run'
Example Response
HTTP/1.1 204 No Content Date: Mon, 22 Jan 2018 22:19:47 GMT ...
Stop Task
POST /service/rest/v1/tasks/{id}/stop
This endpoint allows us to stop an individual task. This is the equivalent of cancelling a task in the repository manager UI. Note that not all tasks will respond to a cancellation request.
For example to stop the "Hello World" task:
curl -u admin:admin123 -X POST 'http://localhost:8081/service/rest/v1/tasks/0261aed9-9f29-447b-8794-f21693b1f9ac/stop'
In this example the "Hello World" task was not running when the stop request was made. We will get a 409 response code that signifies that the requested task was not currently running:
Example Response
HTTP/1.1 409 Conflict Content-Length: 0 Date: Mon, 22 Jan 2018 22:22:33 GMT ...
Create Task
POST /service/rest/v1/tasks/
The Create endpoint allows you to create a task from the API rather than from the user interface. Below is an example for creating a Cleanup Tags task.
curl -X 'POST' \ 'https://localhost:8081/service/rest/v1/tasks' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'NX-ANTI-CSRF-TOKEN: 1.1.1.1' \ -H 'X-Nexus-UI: true' \ -d '{ "type": "tags.cleanup", "name": "Test Tags Cleanup", "enabled": true, "alertEmail": "abc@123.com", "notificationCondition": "FAILURE", "frequency": { "schedule": "once", "startDate": 0, "timeZoneOffset": "+3", "recurringDays": [ 0 ], "cronExpression": "string" } }'
Update Task
PUT /service/rest/v1/tasks/{taskId}
The update endpoint allows you to update an existing task outside of the user interface. You must know the task's ID to update the task. If you do not know a task's ID, use the Get Task endpoint first to find the task and its associated ID.
Below is an example using this endpoint to update the schedule for a Tag Cleanup task.
curl -X 'PUT' \ 'https://localhost:8081/service/rest/v1/tasks/{taskID}' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'NX-ANTI-CSRF-TOKEN: 1.1.1.1' \ -H 'X-Nexus-UI: true' \ -d '{ "name": "Test Tags Cleanup", "enabled": false, "alertEmail": "abc@123.com", "notificationCondition": "FAILURE", "frequency": { "schedule": "daily", "startDate": 0, "timeZoneOffset": "+3", "recurringDays": [ 0 ], "cronExpression": "0 0 12 * * ?" } }'
Delete Task
DELETE /service/rest/v1/tasks/{id}
The Delete Task endpoint allows you to delete an existing task by task ID. If you do not know a task's ID, use the Get Task endpoint first to find the task and its associated ID.
Below is an example of deleting a Tag Cleanup task using its ID.
curl -X 'DELETE' \ 'https://localhost:8081/service/rest/v1/tasks/{taskID}' \ -H 'accept: application/json' \ -H 'NX-ANTI-CSRF-TOKEN: 1.1.1.1' \ -H 'X-Nexus-UI: true'
Get Task Templates
GET /service/rest/v1/tasks/templates
This endpoint allows you to request a list of all task templates present in your Nexus Repository deployment. A template is an object that contains all task properties for that task type just as you would see in the user interface. You can then use a template as a source when constructing requests to create or update tasks.
Below is an example for retrieving all of the task templates in a given deployment:
curl -X 'GET' \ 'https://localhost:8081/service/rest/v1/tasks/templates' \ -H 'accept: application/json' \ -H 'NX-ANTI-CSRF-TOKEN: 1.1.1.1' \ -H 'X-Nexus-UI: true'
Get Task Template by Type
GET /service/rest/v1/tasks/templates/{typeId}
This endpoint allows you to retrieve a specific task template. A template is an object that contains all task properties for that task type just as you would see in the user interface. You can then use the template as a source when constructing requests to create or update tasks.
If you are unsure what typeId
to use, use the Get Task Templates endpoint first to retrieve a list of available tasks and their associated types. The type
field for each available task corresponds to the typeId
that you would enter in this Get Task Template by Type endpoint.
Below is an example for retrieving a Cleanup Tags task template:
curl -X 'GET' \ 'https://localhost:8081/service/rest/v1/tasks/templates/tags.cleanup' \ -H 'accept: application/json' \ -H 'NX-ANTI-CSRF-TOKEN: 1.1.1.1' \ -H 'X-Nexus-UI: true'