ScriptRunner Confluence REST endpoint with @BaseScript, @WithPlugin, and @PluginModule
Asked by Alexander Batis:

I'm trying to create a rest endpoint (in ScriptRunner) which uses the [mywork-confluence-host-plugin java api](https://docs.atlassian.com/mywork-confluence-host-plugin/1.1.9/)

Here's the code :

```
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.mywork.host.service.LocalNotificationServiceImpl
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.atlassian.mywork.mywork-confluence-host-plugin")
@PluginModule LocalNotificationServiceImpl notificationService

@BaseScript CustomEndpointDelegate delegate
someEndpoint(httpMethod: "GET", groups: ["someGroup"]) { MultivaluedMap queryParams, String body ->
 def notifications = notificationService.findAll("someUsername")
 return Response.ok(new JsonBuilder(notifications).toString()).build();
}
```

However, when i include the @PluginModule annotation, the endpoint in ScriptRunner becomes invalid. When i try to hit the endpoint, I get a 404. In my configuration,

What a valid endpoint looks like in my configuration:![api-endpoint-example.PNG](/t5/image/serverpage/image-id/20788i92ED115690B89BE5/image-size/large?v=v2&px=999 "api-endpoint-example.PNG")

What the endpoint using @PluginModule looks like in my configuration:

![api-endpoint-error.PNG](/t5/image/serverpage/image-id/20786i5FE9E724A0AA5135/image-size/large?v=v2&px=999 "api-endpoint-error.PNG")

![api-endpoint-error.PNG](/t5/image/serverpage/image-id/20786i5FE9E724A0AA5135/image-size/large?v=v2&px=999 "api-endpoint-error.PNG")


Answers:
author: Stephen Cheesley [Adaptavist]
body: Hi Alexander,

Do you have any anomalous output in your logs? Any stacktraces or any other errors perhaps?

comments: author: Alexander Batis
body: [@Stephen Cheesley \[Adaptavist\]](/t5/user/viewprofilepage/user-id/916767) It wasn't outputting any logs so after some troubleshooting i disabled the ScriptRunner plugin, thene re-enabled it and the same code runs just fine


author: Alexander Batis
body: [@Stephen Cheesley \[Adaptavist\]](/t5/user/viewprofilepage/user-id/916767) after not running the code for a while, it started giving the following error :

```
{

message: "Cannot invoke method findAll() on null object",

stack-trace: "java.lang.NullPointerException: Cannot invoke method findAll() on null object at Script486$_run_closure1.doCall(Script486.groovy:21) at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.doEndpoint(UserCustomScriptEndpoint.groovy:308) at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.getUserEndpoint(UserCustomScriptEndpoint.groovy:195) ",

status-code: "INTERNAL_SERVER_ERROR"

}
```


author: Stephen Cheesley [Adaptavist]
body: What version of ScriptRunner are you using?


author: Alexander Batis
body: [@Stephen Cheesley \[Adaptavist\]](/t5/user/viewprofilepage/user-id/916767) ScriptRunner version 5.2.12


author: Alexander Batis
body: Here's what the configuration looks like now:

![api-endpoint-error-2.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/20833i22F169548A0FC6C0/image-size/large?v=v2&px=999 "api-endpoint-error-2.PNG")

Also , I haven't changed any of the code, or have even updated it from what you see above.


author: Stephen Cheesley [Adaptavist]
body: Are you using Data Centre or Server?


author: Alexander Batis
body: Data Centre


author: Stephen Cheesley [Adaptavist]
body: I would recommend updating to the latest version of ScriptRunner as we patched some DC issues for REST endpoints in that release


author: Alexander Batis
body: ill give that a shot and ill check back here if I still experience the issue - thanks!


author: Stephen Cheesley [Adaptavist]
body: Hey Alexander,

Did the upgrade fix your issue?


author: Alexander Batis
body: I haven't had any issues since I've upgraded - I'll mark this as resolved. Thanks Stephen!


Tags: confluence-server

server