---
title: Scripts
description: You can interact with the script service over REST, as shown in the following table:
component: pingidm
version: 8.1
page_id: pingidm:rest-api-reference:endpoints/rest-scripts
canonical_url: https://docs.pingidentity.com/pingidm/8.1/rest-api-reference/endpoints/rest-scripts.html
keywords: ["REST API", "Scripts"]
section_ids:
  example_script_compile: Example script compile
  example_script_eval_from_file: Example script eval from file
  script-base64-example: Example script eval Base64 encode/decode
---

# Scripts

You can interact with the script service over REST, as shown in the following table:

| URI                              | HTTP Operation | Description                                                                                                                                                                                                                        |
| -------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| /openidm/script?\_action=compile | POST           | Compiles a script, to validate that it can be executed. Note that this action compiles a script, but does not execute it. A successful compilation returns `true`. An unsuccessful compilation returns the reason for the failure. |
| /openidm/script?\_action=eval    | POST           | Executes a script and returns the result, if any.                                                                                                                                                                                  |

## Example script compile

The following example compiles, but does not execute, the script provided in the JSON payload:

```
curl \
--header "X-OpenIDM-Username: openidm-admin" \
--header "X-OpenIDM-Password: openidm-admin" \
--header "Accept-API-Version: resource=1.0" \
--header "Content-Type: application/json" \
--request POST \
--data '{
  "type": "text/javascript",
  "source": "source.mail ? source.mail.toLowerCase() : null"
}' \
"http://localhost:8080/openidm/script?_action=compile"
True
```

## Example script eval from file

The following example executes the script referenced in the `file` parameter, with the provided input:

```
curl \
--header "X-OpenIDM-Username: openidm-admin" \
--header "X-OpenIDM-Password: openidm-admin" \
--header "Accept-API-Version: resource=1.0" \
--header "Content-Type: application/json" \
--request POST \
--data '{
  "type": "text/javascript",
  "file": "script/autoPurgeAuditRecon.js",
  "globals": {
    "input": {
      "mappings": ["%"],
      "purgeType": "purgeByNumOfRecordsToKeep",
      "numOfRecons": 1
    }
  }
}' \
"http://localhost:8080/openidm/script?_action=eval"
"Must choose to either purge by expired or number of recons to keep"
```

## Example script eval Base64 encode/decode

The following examples evaluate the `atob` (Base64-decode) and `btoa` (Base64-encode) global script bindings:

* atob

* btoa

Request

```none
curl \
--header "X-OpenIDM-Username: openidm-admin" \
--header "X-OpenIDM-Password: openidm-admin" \
--header "Content-Type: application/json" \
--request POST \
--data '{
  "type": "text/javascript",
  "source": "atob(\"SGVsbG8gV29ybGQh\");"
}' \
"http://localhost:8080/openidm/script?_action=eval"
```

Response

```none
"Hello World!"
```

Request

```none
curl \
--header "X-OpenIDM-Username: openidm-admin" \
--header "X-OpenIDM-Password: openidm-admin" \
--header "Content-Type: application/json" \
--request POST \
--data '{
  "type": "text/javascript",
  "source": "btoa(\"Hello World!\");"
}' \
"http://localhost:8080/openidm/script?_action=eval"
```

Response

```none
"SGVsbG8gV29ybGQh"
```

Learn more in [Global utility functions](../../scripting-guide/scripting-func-ref.html#global-utility-functions).
