Creating a user macro in confluence to call rest api in jira .. .not sure what I'm doing wrong?

Hi - i’ve been looking through the docs; I don’t see what I’m doing wrong here? It just goes error function and frankly I’m too new to this to understand what the error is telling me … thanks in advance!

<script type="text/javascript">

    AJS.toInit(function ($) {
        jQuery("#jirabutton").click(function () {
            jQuery.ajax({

                url: contextPath + "/rest/api/2/issue",
                type: "POST",
                dataType: "json",
                data: {
                    fields:
                    {
                        project:
                        {
                            key: "LAUR"
                        },
                        summary: "REST ye merry gentlemen.",
                        description: "Creating of an issue using project keys and issue type names using the REST API",
                        issuetype: {
                            "name": "Story"
                        }
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert('An error occurred... Look at the console (F12 or Ctrl+Shift+I, Console tab) for more information!');

                    $('#result').html('<p>status code: ' + jqXHR.status + '</p><p>errorThrown: ' + errorThrown + '</p><p>jqXHR.responseText:</p><div>' + jqXHR.responseText + '</div>');
                    console.log('jqXHR:');
                    console.log(jqXHR);
                    console.log('textStatus:');
                    console.log(textStatus);
                    console.log('errorThrown:');
                    console.log(errorThrown);
                },

                /**
                 * A function to be called if the request succeeds.
                 */
                success: function (data, textStatus, jqXHR) {
                    $('#result').html(data);
                    alert('Load was performed. Look at the console (F12 or Ctrl+Shift+I, Console tab) for more information! ');
                    console.log('jqXHR:');
                    console.log(jqXHR);
                    console.log('textStatus:');
                    console.log(textStatus);
                    console.log('data:');
                    console.log(data);
                }
            });


        });
    });


</script>

    <button type="button" id="jirabutton">
        Add to jira
</button>

Hi Laura,

Thanks for raising your questions.
It would be nice if you can log the error and see what sort of error is being returned from the rest API. Also, I have few more pointers:

  1. How are you authenticating to Jira?
  2. Can you see the value of contextPath, since you are in confluence and trying to contact Jira, you need to be sure that you have the right URL for Jira.

Thanks,
Ganesh

Hi Ganesh -

I have put an application link between the project i am trying to make the issue in and the confluence space. I was hoping that was enough for authentication? I am an admin user in both. What’s the right way do to do that? I’ve hardcoded in the path as the context path from confluence is for the conflence api. Here is what i am getting back

So that was the content type - I’m setting that now and Im getting a 400. I think that this the authorisation. I want to use the oauth. I’ve set up the application link. How do I do that? Thanks yo very much in advance …