---
title: "Shared Groovy scripts REST API"
canonical: "https://support.appfire.com/space/JMWE/461996245/Shared%20Groovy%20scripts%20REST%20API"
format: markdown
---
> Macro (aura-html)

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

<details>
<summary>Get a Shared script   GET <jira-base-url>/rest/jmwe/1/shared-scripts/<name></summary>

Returns the JSON of the shared script by the script name.

<span style="color: #6554c0">**Request**</span>

###### **URL PARAMETERS**

| **parameter** | **description** |
| --- | --- |
| `name` | Name of the Shared Groovy script |
| `jira-base-url` | Jira base URL. For example http://localhost:8080 |

<span style="color: #6554c0">**Responses**</span>

[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/GreetMe
```

**Response **

```
{
    "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
}
```
</details>

<details>
<summary>Get all shared scripts   GET <jira-base-url>/rest/jmwe/1/shared-scripts</summary>

Returns the JSON of all the shared scripts in the instance

<span style="color: #6554c0">**Request**</span>

###### **URL PARAMETERS**

| **parameter** | **description** |
| --- | --- |
| `jira-base-url` | Jira base URL. For example [http://localhost:8080](http://localhost:8080) |

<span style="color: #6554c0">**Responses**</span>

[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-scripts
```

**Response: **

```
[
    {
        "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.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
    }
]
```
</details>

<details>
<summary>Delete a shared script   DELETE <jira-base-url>/rest/jmwe/1/shared-scripts/<name></summary>

Deletes the specified shared script

<span style="color: #6554c0">**Request**</span>

###### **URL PARAMETERS**

| **parameter** | **description** |
| --- | --- |
| `name` | Name of the Shared Groovy script |
| `jira-base-url` | Jira base URL. For example [http://localhost:8080](http://localhost:8080) |

<span style="color: #6554c0">**Responses**</span>

[STATUS 200] - *application/json *Returned if the shared scripts is deleted.

**EXAMPLE**

```
DELETE http://localhost:8080/rest/jmwe/1/shared-scripts/Functions
```
</details>

<details>
<summary>Create a new shared script   POST <jira-base-url>/rest/jmwe/1/shared-scripts</summary>

Creates a new shared script

<span style="color: #6554c0">**Request**</span>

###### **URL PARAMETERS**

| **parameter** | **description** |
| --- | --- |
| `jira-base-url` | Jira base URL. For example [http://localhost:8080](http://localhost:8080) |

**Body**

```
{
    "id": String,
    "key": String,
    "code": String,
    "description": String
}
```

<span style="color: #6554c0">**Responses**</span>

[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"
}
```
</details>

<details>
<summary>Update a shared script   PUT <jira-base-url>/rest/jmwe/1/shared-scripts/<name></summary>

Updates the specified shared script

<span style="color: #6554c0">**Request**</span>

###### **URL PARAMETERS**

| **parameter** | **description** |
| --- | --- |
| `name` | Name of the Shared Groovy script |
| `jira-base-url` | Jira base URL. For example [http://localhost:8080](http://localhost:8080) |

**Body**

```
{
    "id": String,
    "key": String,
    "code": String,
    "description": String,
    "modified": Long
}
```

<span style="color: #6554c0">**Responses**</span>

[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/getReporter
```

**Body**

```
{
   "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
}
```
</details>

<details>
<summary>Import scripts   POST <jira-base-url>/rest/jmwe/1/shared-scripts/import</summary>

Import shared Groovy scripts. 

<span style="color: #6554c0">**Request**</span>

###### <span style="color: #6554c0">**URL PARAMETERS**</span>

| **parameter** | **description** |
| --- | --- |
| `jira-base-url` | Jira base URL. For example [http://localhost:8080](http://localhost:8080) |

###### <span style="color: #6554c0">**QUERY PARAMETERS**</span>

| **parameter** | **type** | **description** |
| --- | --- | --- |
| `replaceNewer` | Boolean | To force override existing scripts even if the imported script is older or doesn't have a modified data, pass the value `true`. By default, existing scripts will only be replaced if the imported script is newer. |

**Body**

```
[
  {
    "id": String,
    "key": String,
    "code": String,
    "description": String
  },
  {
   "id": String,
   "key": String,
   "code": String,
   "description": String
  }
]
```

<span style="color: #6554c0">**Responses**</span>

[STATUS 200] - *application/json *Returned if the shared scripts are successfully created.

**EXAMPLE 1**

```
POST http://localhost:8080/rest/jmwe/1/shared-scripts/import
```

**Body**

```
[
   {
        "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=true
```

**Body: **

```
[
    {
        "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"
}
```
</details>