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 |
/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
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"
"Hello World!"
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"
"SGVsbG8gV29ybGQh"
Learn more in Global utility functions.