The Adaptavist Group LogoDocumentation

Delete a REST Endpoint That Broke the REST Endpoint Page

Remedy for the problem of creating a REST endpoint that causes the REST Endpoints page to fail to load.

Problem

You created a REST endpoint that had some code that caused the REST endpoints page to fail to load.

Tip: Support

For Support to tell you why the failure happened, please send us the script that caused the problem so we can reproduce the issue.

Solution

Warning: Identifying the broken REST endpoint

We assume you know which REST endpoint caused the issue. If you do not, please contact Support.

Proceed with the following solution to delete the REST endpoint that caused the issue:

  1. Run the following script from the Script Console to get the REST endpoint data, so you can find the ID of the endpoint.

    Get REST endpoints from the Script Console

    import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
    import com.onresolve.scriptrunner.runner.RestEndpointManager
    import com.onresolve.scriptrunner.canned.ConfiguredObjectMapper
     
    def restEndpointManager = ScriptRunnerImpl.scriptRunner.getBean(RestEndpointManager)
    def objectMapper = ScriptRunnerImpl.scriptRunner.getBean(ConfiguredObjectMapper).get()
     
    def result = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(restEndpointManager.load())
     
    "<pre>$result</pre>"

    Example Result: The following example output is of two REST Endpoints.

    Tip: Protect against data loss

    Make a copy of this output in case you delete the wrong REST endpoint.

    JSON output example

    [ {
     "id" : "99048e03-21b8-4109-bbe9-94fc9324592b",
     "version" : 1,
     "ownedBy" : null,
     "disabled" : false,
     "FIELD_SCRIPT_FILE_OR_SCRIPT" : {
     "script" : "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
    
    @BaseScript CustomEndpointDelegate delegate
    
    doItAgain(httpMethod: \"GET\", groups: [\"jira-administrators\"]) { MultivaluedMap queryParams, String body ->
        return Response.ok(new JsonBuilder([abc: 42]).toString()).build();
    }
    ",
     "scriptPath" : null,
     "parameters" : { }
      },
     "FIELD_NOTES" : "another end point",
     "canned-script" : "com.onresolve.scriptrunner.canned.common.rest.CustomRestEndpoint"
    }, {
     "id" : "0e479c4c-be29-41a9-aeb5-ed84a94a8706",
     "version" : 1,
     "ownedBy" : null,
     "disabled" : false,
     "FIELD_SCRIPT_FILE_OR_SCRIPT" : {
     "script" : "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
    
    @BaseScript CustomEndpointDelegate delegate
    
    doThisThing(httpMethod: \"GET\", groups: [\"jira-administrators\"]) { MultivaluedMap queryParams, String body ->
        return Response.ok(new JsonBuilder([total: 87845485]).toString()).build();
    }
    ",
     "scriptPath" : null,
     "parameters" : { }
      },
     "FIELD_NOTES" : null,
     "canned-script" : "com.onresolve.scriptrunner.canned.common.rest.CustomRestEndpoint"
    } ]

    Each REST endpoint has a "FIELD_SCRIPT_FILE_OR_SCRIPT" section, and in this section there is a "script" section which contains your REST endpoint's inline code.

  2. Review the "script" section to find the broken REST endpoint.
  3. Once you have found the broken endpoint, look for the "id" element above the "FIELD_SCRIPT_FILE_OR_SCRIPT" section.

    For example, in the above output, the id "99048e03-21b8-4109-bbe9-94fc9324592b" is for the first REST endpoint. You can use this ID to delete the problem REST endpoint.

  4. Open your terminal or application that lets you run CURL requests.
  5. Run this command to delete the problem endpoint:
    Example CURL command template
    curl -X DELETE -u <AdminUser>:<AdminPassword> <BASE_URL>/rest/scriptrunner/latest/custom/customadmin/<ID OF YOUR ENDPOINT>
     
    //Replace the <AdminUser>, <AdminPassword> and <ID_OF_YOUR_ENDPOINT> with the values specific to your environment.
  6. After running the command, go back to your Jira user interface, clear the browser cache, and then reload the REST endpoints page.

Result

If you successfully deleted the endpoint, it should not show anymore, and the first script should also not return any information on the deleted endpoint.

Search documentation

Start typing to search the docs.