Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Submit form to custom rest (POST)

Hey,

I'm trying to submit an HTML form in JIRA dialog.

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

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

@BaseScript CustomEndpointDelegate delegate

showDialog(){ MultivaluedMap queryParams ->

    // get a reference to the current page...     def issuekey = queryParams.getFirst("issuekey")


    def dialog =
        """<section role="dialog" id="sr-dialog" class="aui-layer aui-dialog2 aui-dialog2-medium" aria-hidden="true" data-aui-remove-on-hide="true">
            <header class="aui-dialog2-header">
                <h2 class="aui-dialog2-header-main">Send comment</h2>
                <a class="aui-dialog2-header-close">
                    <span class="aui-icon aui-icon-small aui-iconfont-close-dialog">Close</span>
                </a>
            </header>
            <div class="aui-dialog2-content">
                <p>
                <form action="http://localhost:8080/rest/scriptrunner/latest/custom/sendcomment" method="post" id="usrform" class="aui" enctype='application/json'>                 <fieldset>
                <textarea class="textarea" name="comment" id="textarea-id" placeholder="Your comment here..."></textarea>
                </fieldset>
                <input id='issuekey' type="hidden" name="issuekey" value='"""+issuekey+"""'>
                <div class="buttons">
                <input class="button submit" type="submit" value="Submit" id="comment-save-button">
                </div>
                </form>
                </p>
            </div>
            <footer class="aui-dialog2-footer">
                <div class="aui-dialog2-footer-actions">
                    <button id="dialog-close-button" class="aui-button aui-button-link">Close</button>
                </div>
                <div class="aui-dialog2-footer-hint"></div>
            </footer>
        </section>
        """

    Response.ok().type(MediaType.TEXT_HTML).entity(dialog.toString()).build()
}

 

The problem is that I get "XSRF check failed" error.

I even tried to just print a log from the custom rest but I it does not print to the logs.

I get this is the log error:

2018-04-04 11:58:54,477 http-nio-8080-exec-4 WARN admin 718x3452x1 jr3nl4 0:0:0:0:0:0:0:1 /rest/scriptrunner/latest/custom/sendcomment [c.a.p.r.c.security.jersey.XsrfResourceFilter] XSRF checks failed for request: http://localhost:8080/rest/scriptrunner/latest/custom/sendcomment , origin: http://localhost:8080 , referrer: http://localhost:8080/projects/STAR/issues/STAR-1

I saw that the solution it submit the form with JQuery but It's not recommended to add <script> tag to inline groovy code

add this to the post header- "X-Atlassian-Token", "nocheck"

Is anybody know a way to add it to the HTML code?

Thanks

1 answer

0 votes

Hi! 

 

Have you implemented it? https://stackoverflow.com/questions/9516865/how-to-set-a-header-field-on-post-a-form

But you can do it as ajax function 

like this 

$.ajax({    url: 'foo/bar',    headers: { 'X-Atlassian-Token': 'nocheck' }
});

 

Cheers,

Gonchik Tsymzhitov 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

116 views 1 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you