# Managing and Running Scripts

Once you have completed the creation of your script, you need to publish it to the repository manager for execution. This is done by REST API invocations or through the UI.

To run a script from the Nexus Repository UI, you must create a scheduled task. Navigate to _Tasks_ from the _Settings_ 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.

```
http://localhost:8081/service/rest/v1/script
```

This endpoint accepts JSON-formatted payloads with your script as the `content`.

Example JSON formatted file `maven.json` with a simple repository creation script:

```
{
  "name": "maven",
  "type": "groovy",
  "content": "repository.createMavenHosted('private')"
}
```

The JSON file `maven.json` located in the current directory can be published to the repository manager with an HTTP POST like:

```
curl -v -X POST -u admin:admin123 --header "Content-Type: application/json" 'http://localhost:8081/service/rest/v1/script' -d @maven.json
```

A list of scripts stored on the repository manager can be accessed with:

```
curl -v -X GET -u admin:admin123 'http://localhost:8081/service/rest/v1/script'
```

The same call with a script name appended returns the actual script content.

A script can be executed by sending a POST to the run method of the specific script.

```
curl -v -X POST -u admin:admin123 --header "Content-Type: text/plain" 'http://localhost:8081/service/rest/v1/script/maven/run'
```

A successful execution should result in a `HTTP/1.1 200 OK`.

Scripts can be removed with a HTTP DELETE operation to the specific script:

```
curl -v -X DELETE -u admin:admin123 'http://localhost:8081/service/rest/v1/script/maven'
```

## Parameters

Scripts can receive run-time parameters via the REST API:

```
curl -v -X POST -u admin:admin123 --header "Content-Type: text/plain" 'http://localhost:8081/service/rest/v1/script/updateAnonymousAccess/run' -d 'false'
```

and receive them as arguments that have to be parsed by the script as desired:

```
security.setAnonymousAccess(Boolean.valueOf(args))
```

Multiple parameters can be passed in via a JSON file in the POST request:

`params.json`:

```
{
"repoName":"snapshots",
"groupId":"org.some.project",
"artifactId":"someartifact"
}
```

Then the command would be similar to the following:

```
curl -k -u user:pass -X POST --header 'Content-Type: text/plain' http://localhost:8081/service/rest/v1/script/rebuild-maven-metadata/run -d @params.json
```

And you can access the parameters in your script code:

```
def request = new JsonSlurper().parseText(args);
assert request.repoName: 'repoName parameter is required';
assert request.groupId: 'groupId parameter is required';
assert request.artifactId: 'artifactId parameter is required';
```

Interaction with the REST API for scripts can be done with any scripting language capable of HTTP calls as mentioned above. In the following section you can find some further detailed examples.
