

Last date modified: April 15 2025
In Relativity, you can execute SQL scripts through the UI that act on the databases backing an instance. You can implement these scripts to customize and extend Relativity functionality. For more information, see Scripts on the Relativity
The Relativity Script Manager API service exposes endpoints for interacting with scripts as follows:
Use this service to create standalone applications that manage scripts across multiple environments or across workspaces in a single environment.
You can also use the Script service through .NET. For more information, see Script Manager API.
You can use the Postman sample file to become familiar with making calls to endpoints on the Script Manager service. To download the sample file, click Script Manager Postman file.
To get started with Postman, complete these steps:
Review the following guidelines for working with this service.
The URLs for REST endpoints contain path parameters that you need to set before making a call:
For example, you can use the following URL to update a script:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/{scriptID}
Set the path parameters as follows:
To use the Script Manager service, send requests by making calls with the required HTTP methods. You can use the following .NET code as a sample client for creating a script.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public async Task<int> CreateScriptAsync()
{
int scriptID = 0;
using (Relativity.Extensibility.{versionNumber}.Scripts.IScriptManager scriptManager = serviceFactory.CreateProxy<Relativity.Extensibility.{versionNumber}.Scripts.IScriptManager>())
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("X-CSRF-Header", "-");
client.DefaultRequestHeaders.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes("<user login>:<user password>")));
client.DefaultRequestHeaders.Add("X-Kepler-Version", "2.0");
client.BaseAddress = new Uri("http://<host name>/");
string inputJSON = @"{""ScriptRequest"":{""ScriptBody"":""<script><name>My script Name</name><description>About my script</description><category></category><input> <constant id=\""count\"" name=\""Rows\"" type=\""number\"" /></input><display type =\""itemlist\""/><action returns =\""table\""><![CDATA[ SELECT TOP(CAST(#count# AS INT)) * FROM [eddsdbo].[Artifact] ]]></action></script>"",""RelativityApplications"": []}}";
string url = "/Relativity.rest/api/relativity-extensibility/{versionNumber}/workspaces/-1/scripts";
HttpResponseMessage response = await client.PostAsync(url, new StringContent(inputJSON, Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode();
string content = await response.Content.ReadAsStringAsync();
scriptID = Int32.Parse(content);
}
return scriptID;
}
To create a new relativity script in the specified workspace, send a POST request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts
The request must contain the following fields:
1
2
3
4
5
6
7
8
9
10
11
{
"ScriptRequest":
{
"ScriptBody": "<script><name>My script Name</name><description>About my script</description><category></category><input> <constant id=\"count\" name=\"Rows\" type=\"number\" /></input><display type =\"itemlist\"/><action returns =\"table\"><![CDATA[ SELECT TOP(10) * FROM[eddsdbo].[Artifact] ]]></action></script>",
"RelativityApplications": [
{
"ArtifactID": 123456
}
]
}
}
The response is an integer representing the Artifact ID of the created script.
1
123456
To retrieve information, including script body, about specified script, send a GET request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/{scriptID}
If you would need to retrieve metadata and actions in addition to the script information, you can modify the endpoint as follows:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/{scriptID}/true/true
The body of the request is empty.
The response contains the following fields:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
"Category": "",
"Description": "About my script",
"IsLinkedScript": false,
"Key": "",
"ReportGroupURL": "%ApplicationPath%/Case/RelativityScript/Run.aspx?%AppID%&%SystemID%&category=",
"ScriptBody": "<script>\r\n\t<name>My script Name</name>\r\n\t<description>About my script</description>\r\n\t<category></category>\r\n\t<input />\r\n\t<display type=\"itemlist\" />\r\n\t<action returns=\"table\"><![CDATA[\n\t\t\t\t\t\t\n\t\t\t\t\t\t\tSELECT TOP(10) * FROM [eddsdbo].[Artifact]\n\t\t\t\t\t\t]]></action>\r\n</script>",
"Version": "",
"CreatedOn": "2020-06-12T19:51:49.79",
"CreatedBy": {
"Name": "Admin, Relativity",
"ArtifactID": 9,
"Guids": []
},
"LastModifiedBy": {
"Name": "Admin, Relativity",
"ArtifactID": 9,
"Guids": []
},
"LastModifiedOn": "2020-06-12T19:51:49.79",
"Meta": {
"Unsupported": [
"RelativityApplications"
],
"ReadOnly": []
},
"Actions": [
{
"Name": "Delete",
"Href": "relativity-extensibility/{versionNumber}/workspaces/-1/scripts/1021654",
"Verb": "DELETE",
"IsAvailable": true,
"Reason": []
},
{
"Name": "Update",
"Href": "relativity-extensibility/{versionNumber}/workspaces/-1/scripts/1021654",
"Verb": "PUT",
"IsAvailable": true,
"Reason": []
}
]
"Name": "My script Name",
"ArtifactID": 1021654,
"Guids": []
}
To modify an existing script, send a PUT request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/{scriptID}
See the following sample JSON request:
1
2
3
4
5
6
7
8
9
10
11
{
"ScriptRequest":
{
"ScriptBody": "<script><name>My script Name</name><description>About my script</description><category></category><input /><display type =\"itemlist\"/><action returns =\"table\"><![CDATA[ SELECT TOP(10) * FROM[eddsdbo].[Artifact] ]]></action></script>",
"RelativityApplications": [
{
"ArtifactID": 123456
}
]
}
}
When the script is successfully updated, the response contains the status code of 200. If an error occurred parsing the script body or the Artifact ID is invalid, a status code of 400 is returned.
To delete an existing script, send a DELETE request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/{scriptID}
Note: Deleting a script from the admin library also removes delete any copies imported into workspaces.
The request body is empty.
When the script is successfully deleted, the response contains the status code of 200. If the workspace ID or the Artifact ID is invalid, a status code of 400 is returned.
To import a script from the admin library to the workspace script library, send a POST request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/import
The request must contain the following fields:
1
2
3
4
5
6
7
8
9
10
11
12
{
"ScriptImportRequest":{
"LibraryScript":{
"ArtifactID": 123456
},
"RelativityApplications": [
{
"ArtifactID": 789123
}
]
}
}
When a script is successfully imported, the response contains the Artifact ID of the script in the target workspace that was specified in the endpoint.
1
456789
To retrieve a list of the input parameters defined a script, send a GET request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/{scriptID}/parameters
The request body is empty.
The response contains the following fields:
1
2
3
4
5
6
7
8
9
10
11
12
13
[
{
"Name": "Rows",
"Identifier": "count",
"IsRequired": true,
"Type": "Number",
"Attributes": {
"precision": "18",
"scale": "0"
},
"PossibleValues": []
}
]
To preview a script body with input values before running it, send a GET request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/{scriptID}/preview
The request must contain the following fields:
1
2
3
4
5
6
7
8
{
"Inputs": [
{
"Identifier": "count",
"Value": "25"
}
]
}
When a preview request is successful, the response contains a string representing the SQL executed when the script runs, and the input parameters applied.
1
"EXECUTE sp_executesql N'SELECT TOP(CAST(@count AS INT)) * FROM [eddsdbo].[Artifact]', N'@count DECIMAL(18,0)', 22"
This section contains endpoints and JSON samples that illustrate how to run jobs, query for results, export results, and clean up script jobs.
Note: You should call the CleanupRunJobAsync method once querying the results of your script job has finished.
To queue a script for running, send a POST request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/{scriptID}/run
The request must contain the following fields:
1
2
3
4
5
6
7
8
9
{
"Inputs": [
{
"Identifier": "count",
"Value": "25"
}
],
"TimeZoneOffset": 0
}
When an enqueue request is successful, the response contains a unique script run job identifier used for checking job status, and querying and exporting script results.
1
"RunJobID": "a081c453-ae0d-44f4-a204-def5e556a396"
To return the status of the script run job and each action contained in the script, send a GET request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/run-jobs/{runJobID}
Note: The runJobID is a GUID.
The request body is empty.
The response contains the following fields about the state of the script job and the individual actions:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"Status": "Completed",
"ActionJobs": [
{
"Name": "",
"ReturnType": "Table",
"AllowHtmlTagsInOutput": false,
"ErrorMessage": "",
"Columns": [
{
"Name": "ArtifactID",
"DataType": "Number"
},
...
],
"RowsAffected": 0,
"Status": "Completed"
}
],
"ErrorMessage": ""
}
To return completed script action results that match query filter and sort criteria, send a POST request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/run-jobs/{runJobID}/actions/{actionIndex}/query-results
Set the path parameters as follows:
The request must contain the following fields:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"ActionQueryRequest":
{
"Condition":"'TextIdentifier' LIKE 'important'",
"Sorts":
[
{
"ColumnName": "TextIdentifier",
"Direction": "Ascending"
}
],
"ColumnNames":
[
"TextIdentifier"
"ArtifactID"
]
},
"Start": 0,
"Length": 10
}
A successful query action job request returns all the results from the specified script run action that meet the query criteria in the request.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
"TotalCount": 25,
"Rows": [
{
"Values": [
"Active",
662
]
},
{
"Values": [
"Admin Mode",
-1
]
},
...
{
"Values": [
"WorkspacesOnPicker",
359
]
}
],
"Columns": [
{
"Name": "TextIdentifier",
"DataType": "Text"
},
{
"Name": "ArtifactID",
"DataType": "Number"
}
],
"CurrentStartIndex": 0,
"ResultCount": 25
}
To export completed script action results that match query filter/sort conditions, send a POST request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/run-jobs/{runJobID}/actions/{actionIndex}/export-results
Set the path parameters as follows:
The request must contain the following fields:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"ActionExportRequest": {
"QueryRequest": {
"Condition": "",
"Sorts": [
{
"ColumnName": "TextIdentifier",
"Direction": "Ascending"
}
],
"ColumnNames": [
"*"
]
}
}
}
A successful export action job request returns all the specified results from the script action as a CSV text file.
1
2
3
4
5
6
7
"ArtifactID","ArtifactTypeID","ParentArtifactID","AccessControlListID","AccessControlListIsInherited","CreatedOn","LastModifiedOn","LastModifiedBy","CreatedBy","TextIdentifier","ContainerID","Keywords","Notes","DeleteFlag",
"662","7","62","1","True","1/1/2007 12:00:00 AM","1/1/2007 12:00:00 AM","9","9","Active","62"," "," ","False",
"'-1","8","62","1","False","9/29/2014 3:32:47 PM","9/29/2014 3:32:47 PM","9","9","Admin Mode","62","","Admin Workspace - to be used for admin permissions only","False",
...
"359","4","62","1","True","1/1/2007 12:00:00 AM","8/5/2008 12:38:34 AM","9","9","WorkspacesOnPicker","62","","","False",
To return completed script results (for all actions) that match query filter/sort conditions, send a POST request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/run-jobs/{runJobID}/export-report
Note: The runJobID is a GUID.
The request must contain the following fields:
1
2
3
4
5
6
{
"ScriptExportRequest":
{
"FileType": "PDF"
}
}
A successful export script report request returns the script results in the specified file format.
To clean up all temporary tables created as part of a script run job, send a DELETE request with a URL in the following format:
1
<host>/Relativity.Rest/api/relativity-extensibility/{versionNumber}/workspaces/{workspaceID}/scripts/run-jobs/{runJobID}
Note: The runJobID is a GUID.
The request body is empty.
There is no response body.
Note: After you call this endpoint, the script results are no longer available for query or export.
Why was this not helpful?
Check one that applies.
Thank you for your feedback.
Want to tell us more?
Great!
Additional Resources |
|||
DevHelp Community | GitHub | Release Notes | NuGet |