I have a fragment(button) that calls a rest endpoint, this works great and is pretty simple. The Rest Endpoint queries data and returns the result which updates the issue. This works great, for certain conditions we want to setup a listener to automatically initiate the logic defined in the rest endpoint, struggling with how to reference this.
Within a listener is it possible to call an already defined rest endpoint script instead of re-doing it? What format is it expecting to pass a string parameter such as an issue key?
This seems like it should be an easy reference I'm missing, perhaps it's not possible to reference the endpoints from the listeners? Thanks
@BaseScript CustomEndpointDelegate delegate
doSomething(issue.key)
The above will error and adding {} after it will create a child reference within the existing script and also update the permission of the endpoint to anonymous.
com.atlassian.jira.event.issue.IssueEvent, file: null groovy.lang.MissingMethodException: No signature of method
Hi @Peterr ,
It's is possible to your Listener call your Rest endpoint, you basically will need to access using REST API; Instead of rewriting the rest endpoint method in the Listener, you can call the rest endpoint using REST.
Here is an example about how you can do a POST using Scriptrunner to integrate with Slack, imagine that you need to change from Slack to your Rest Endpoint passing the data you have an example that I have here in my localhost environment that return all components from projectKey Auto (http://192.168.0.17:8080/rest/scriptrunner/latest/custom/getComponent?projectKey=AUTO) you will need to change to your endpoint;
I think that your RES Endpoint expect a GET function, but you get the idea. I recommend you to test first before implementing this in production.
Hello,
I feel my issue has more to do with permissions on the GET request to the ScriptRunner Rest Endpoint. You can restrict the endpoint to various groups, however if I have a listener running that gets triggered from an automated workflow action and a ticket is created/updated the listener logic executes. When it executes it is doing so as the system but not necessarily a particular user that I can restrict the rest endpoint to.
I found that if I remove any permission restriction it sets the group to anonymous and can be called, this would not be viable for us. Is there a security group restriction that we can limit system internal calls or any other secure means to have it perform the call locally without setting it to anonymous or hard-coding credentials?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Peterr ,
This is a great question, I think it might be possible to execute rest api calls authenticated as user in JIRA Server but I'm not sure how.
Maybe you can do is to have a shared code with the logic you need using Script Editor https://scriptrunner.adaptavist.com/6.4.0/jira/script-editor.html and use the shared code in your Listener and your Rest Endpoint, making this way the call through JAVA API.
I'll do a quick example here and share with you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So the first step is to access your script editor
http://192.168.0.17:8080/plugins/servlet/scriptrunner/admin/scriptEditor
Then you can create a folder to organize your code, in my example I created a helper folder.
Then you can add here the code that does all the heavy work and you would like to share it with your Listener and Rest endpoint, in my case my code will return all components from a project key, and it can filter by what the user is typing ( I had this from a previous question),
Here you can find my code:
https://gist.github.com/ItaloQualisoni/1c9791eb08f4e112a6a8b09015ce208e
Then you can use this code importing your new class in your Rest endpoint , workflow condition/validator/post-function or Listener, simple example here how to import and run in Console:
And you can then reuse in your Listener in the same way, below is how I did in my example:
https://gist.github.com/ItaloQualisoni/4c9e049f309c34b999a04afcd681727a
Notice that I've used a singleton pattern so all usage will use the same object, but feels free to test and do as you need. This way to can leave the REST endpoint for the integration you are looking for and if you need to access the shared code you can import and do it through JAVA API instead of calling a rest function.
Let me know if you have any question on that and if that helps you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
More about Script Editor here: https://www.youtube.com/watch?v=Zq9ek71Zp6I
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this doesn't solve the problem calling a restricted Scriptrunner REST Endpoint from a workflow event while it is an anonymous user...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.