Trouble with basic REST API call in Jira Gadget

Hey everyone, I’m stuck trying to make a simple Jira gadget. I made a basic Java class with a REST endpoint, but my gadget won’t talk to it. Here’s what I’ve got:

<!-- Gadget XML snippet -->
<script type="text/javascript">
(function () {
  var gadget = AJS.Gadget({
    baseUrl: "__ATLASSIAN_BASE_URL__",
    view: {
      template: function(args) {
        alert("Start");
        this.getView().html(args.message);
        alert("End");
      },
      args: [{
        key: "message",
        ajaxOptions: function () {
          return { url: "/rest/my-api/1.0/Greeter/sayHi" };
        }
      }]
    }
  });
})();
</script>
// Java class
@Path("/Greeter")
@AnonymousAllowed
@Produces(MediaType.TEXT_HTML)
public class Greeter {
  @GET
  @Path("/sayHi")
  public Response greet() {
    return Response.ok("Hi there!").build();
  }
}

I notice the REST call works in Firebug, but the alerts never show up. Also, I’m getting a big error about no root resource classes in my console. Any suggestions on what might be wrong? I can share my POM file if needed. Thanks!

I’ve dealt with similar issues when creating Jira gadgets. From what I can see, there might be a couple of things going on here.

First, check if your REST endpoint is properly registered. The ‘no root resource classes’ error often means Jira can’t find your REST resource. Make sure your class is properly annotated and picked up by the component scanner.

Secondly, the alerts not showing up suggests a JavaScript error might be occurring before they’re reached. Try adding a try-catch block around your gadget code to see if any errors are being swallowed.

Lastly, double-check your gadget XML. Sometimes, the baseUrl can cause issues if it’s not correctly set. Try hardcoding the full URL to your REST endpoint temporarily to see if that helps.

If none of these solve it, it might be worth sharing your POM file. There could be a dependency issue or a problem with how the plugin is being built.

hey noah, sounds like a tricky one. have u checked if ur REST endpoint is actually registered properly? that error bout no root resource classes usually means jira cant find it. also, try wrapping ur gadget code in a try-catch to see if theres any JS errors happening. could be why ur alerts arent showing up. good luck!

Having worked with Jira gadgets, I can suggest a few things to troubleshoot your issue. First, ensure your REST endpoint is properly registered in Jira’s component scanner. The ‘no root resource classes’ error often indicates this problem. Check your atlassian-plugin.xml file to confirm the REST module is correctly defined.

Next, try simplifying your gadget code. Remove the AJAX call temporarily and hardcode a message to see if the gadget renders at all. This can help isolate whether the issue is with the gadget itself or the REST communication.

Also, verify your REST endpoint’s URL. Sometimes, the context path can be tricky in Jira plugins. Try using the full path, including any necessary prefixes like ‘/plugins/servlet’.

If these steps don’t resolve the issue, consider using browser developer tools to monitor the network requests. This can provide more insight into what’s happening when your gadget tries to communicate with the REST endpoint.