Shared Groovy scripts REST API
This document details the Shared Groovy Scripts REST API of JMWE using which you can import and export shared Groovy scripts within or across Jira instances.
Resources
Returns the JSON of the shared script by the script name.
Request
URL PARAMETERS
parameter | description |
|---|
parameter | description |
|---|---|
| Name of the Shared Groovy script |
| Jira base URL. For example http://localhost:8080 |
Responses
STATUS 200 - application/json Returned if the shared script is found.
STATUS 401 - Unauthorized
STATUS 404 - Not found
EXAMPLE
GET http://localhost:8080/rest/jmwe/1/shared-scripts/GreetMeResponse
{
"id": "GreetMe",
"key": "GreetMe",
"code": "class GreetMe{\r\n String aString = \"Hello\"\r\n String sayIt() {\r\n return aString;\r\n\t} \r\n}",
"description": "",
"modified": 1575641794486
}Returns the JSON of all the shared scripts in the instance
Request
URL PARAMETERS
parameter | description |
|---|
parameter | description |
|---|---|
| Jira base URL. For example http://localhost:8080 |
Responses
STATUS 200 - application/json Returned if the shared scripts are found.
STATUS 401 - Unauthorized
STATUS 404 - Not found
EXAMPLE
GET https://localhost:8080/rest/jmwe/1/shared-scriptsResponse:
[
{
"id": "Functions",
"key": "Functions",
"code": "issue.reporter.name?:issue.assignee.name ",
"description": "",
"modified": 1587603663296
},
{
"id": "GreetMe",
"key": "GreetMe",
"code": "class GreetMe{\r\n String aString = \"Hello\"\r\n String sayIt() {\r\n return aString;\r\n\t} \r\n}",
"description": "",
"modified": 1575641794486
},
{
"id": "ViewIssueClient",
"key": "ViewIssueClient",
"code": "import com.atlassian.jira.com.rproxy.goskope.component.ComponentAccessor;\r\nstatic callingName(issue){\r\nreturn issue.get(\"summary\");\r\n}",
"description": "",
"modified": 1576652611759
},
{
"id": "reportername1",
"key": "reportername1",
"code": "issue.get('reporter').displayName",
"description": "Reporter Name",
"modified": 1585278345351
},
{
"id": "reportername4",
"key": "reportername4",
"code": "issue.get('reporter').displayName",
"description": "Reporter Name",
"modified": 1585278639464
},
{
"id": "getReporter",
"key": "getReporter",
"code": "class DEF{\r\n String getreporter(){\r\n return issue.reporter.name\r\n }\r\n}",
"description": "Get Reporter",
"modified": 1588918528088
}
]
Deletes the specified shared script
Request
URL PARAMETERS
parameter | description |
|---|
parameter | description |
|---|---|
| Name of the Shared Groovy script |
| Jira base URL. For example http://localhost:8080 |
Responses
STATUS 200 - application/json Returned if the shared scripts is deleted.
EXAMPLE
DELETE http://localhost:8080/rest/jmwe/1/shared-scripts/Functions
Creates a new shared script
Request
URL PARAMETERS
parameter | description |
|---|
parameter | description |
|---|---|
| Jira base URL. For example http://localhost:8080 |
Body
{
"id": String,
"key": String,
"code": String,
"description": String
}Responses
STATUS 201 - application/json Returned if the shared script is created.
EXAMPLE
POST http://192.168.5.102:8080/rest/jmwe/1/shared-scripts/Body
{
"id": "getReporter",
"key": "getReporter",
"code": "class DEF{\r\n String getreporter(){\r\n return issue.reporter.name\r\n }\r\n}",
"description": "Get Reporter"
}Response
{
"id": "getReporter",
"key": "getReporter",
"code": "class DEF{\r\n String getreporter(){\r\n return issue.reporter.name\r\n }\r\n}",
"description": "Get Reporter"
}Updates the specified shared script
Request
URL PARAMETERS
parameter | description |
|---|
parameter | description |
|---|---|
| Name of the Shared Groovy script |
| Jira base URL. For example http://localhost:8080 |
Body
{
"id": String,
"key": String,
"code": String,
"description": String,
"modified": Long
}Responses
STATUS 200 - application/json Returned if the shared script is successfully updated.
EXAMPLE
https://jira8-jira8-rvijji.media.innovalog.com/rest/jmwe/1/shared-scripts/getReporterBody
{
"id": "getReporter",
"key": "getReporter",
"code": "issue.get('reporter').displayName",
"description": "Return Reporter Display Name",
"modified": 1585278345351
}Response
{
"id": "getReporter",
"key": "getReporter",
"code": "issue.get('reporter').displayName",
"description": "Return Reporter Display Name",
"modified": 1585278345351
}Import shared Groovy scripts.
Request
URL PARAMETERS
parameter | description |
|---|
parameter | description |
|---|---|
| Jira base URL. For example http://localhost:8080 |
QUERY PARAMETERS
parameter | type | description |
|---|
parameter | type | description |
|---|---|---|
| Boolean | To force override existing scripts even if the imported script is older or doesn't have a modified data, pass the value |
Body
[
{
"id": String,
"key": String,
"code": String,
"description": String
},
{
"id": String,
"key": String,
"code": String,
"description": String
}
]Responses
STATUS 200 - application/json Returned if the shared scripts are successfully created.
EXAMPLE 1
POST http://localhost:8080/rest/jmwe/1/shared-scripts/importBody
[
{
"id": "Functions",
"key": "Functions",
"code": "issue.reporter.name?:issue.assignee.name",
"description": "testing1"
},
{
"id": "GreetMe",
"key": "GreetMe",
"code": "class GreetMe{\r\n String aString = \"Hello\"\r\n String sayIt() {\r\n return aString;\r\n\t} \r\n}",
"description": "testing1"
}
]
Response
{
"GreetMe": "added",
"Functions": "added"
}EXAMPLE 2
POST http://localhost:8080/rest/jmwe/1/shared-scripts/import?replaceNewer=trueBody:
[
{
"id": "Functions",
"key": "Functions",
"code": "issue.reporter.displayName?:issue.assignee.displayName",
"description": "testing"
},
{
"id": "GreetMe",
"key": "GreetMe",
"code": "class GreetMe{\r\n String aString = \"Hello\"\r\n String sayIt() {\r\n return aString;\r\n\t} \r\n}",
"description": "testing"
}
]Response
{
"GreetMe": "replaced",
"Functions": "replaced"
}