REST and Integration API
REST API
The REST API can be used to integrate the repository manager with external systems. Nexus Repository leverages Open API to document the REST API. To make it easier to consume, we ship Nexus Repository with Swagger UI - a simple, interactive user interface, where parameters can be filled out and REST calls made directly through the UI to see the results in the browser. This interface is available under the API item via the System sub menu of the Administrationmenu and requires nx-settings-read privilege to access it. NOTE: The nx-settings privileges give access to multiple views. There is no setting to view only the API at this time. Also, when viewing the API all APIs and their examples and models are shown, however, only the APIs that the user has permission to utilize will function.
For those who wish to work with the API outside of Nexus Repository, we serve an Open API Document at <nexus_url>/service/rest/swagger.json
which always represents the API available on running instance and does not require any privilege to access it. This document can be imported into Postman to work with it interactively, Swagger Codegen to generate a programmatic client, or other tools compatible with Open API Specification.
Note
APIs with /beta endpoints are fully supported by Sonatype, will not be removed and are safe to use in production systems. Compatible newer versions may have aliases allowing newer functionality without any change.
Scripting API
Warning
In order to make Nexus Repository more secure, we have disabled Groovy scripting engine by default. This affects Groovy scripts as used through the REST API and through scheduled tasks.
Nexus Repository also provides a scripting API. Scripts can be written to perform custom tasks that can't be handled directly through the UI or the REST API. Nexus Repository scripts are written in the Groovy programming language. More information about Groovy can be found at http://groovy-lang.org/.
There are several methods to run scripts, including:
To run a script from the Nexus Repository UI, you must create a scheduled task. Navigate to Tasks from the Administration menu, and create a task of type Admin - Execute script . Enter the script source into the Source form field. Set the task frequency to Manual (or another setting to execute on a schedule) and save. The script can then be executed by selecting it from the list of tasks and pressing the Run button.
A script may be uploaded and run through the REST Script API.
Nexus Repository provides the following APIs to scripts:
Core API: allows a script to set global configuration options
Security API: allows a script to add users, roles, and privileges
Blob Store API: allows a script to create new blob stores
Repository API: provides a simple, format-specific interface for creating repositories
Sample scripts and javadoc API documentation can be found at https://github.com/sonatype-nexus-community/nexus-scripting-examples.
For recommendations on configuring a stable scripting environment and tips from Sonatype, see this knowledge base article.