How to retrieve current issue id

Hi,

I have created a small test app. It contains only one web_panel with a button. I would like to retrieve id of the current issue the panel is displayed within.

Here is my panel source:

<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://unpkg.com/@atlaskit/css-reset@2.0.0/dist/bundle.css" media="all">

<script src="https://connect-cdn.atl-paas.net/all.js" async></script>
<!-- jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<!-- Atlassian User Interface (AUI) -->
<link rel="stylesheet" href="//aui-cdn.atlassian.com/aui-adg/5.7.0/css/aui.css" media="all">
<script src="//aui-cdn.atlassian.com/aui-adg/5.7.0/js/aui.js"></script>

<script>
function someTest () {
  console.log('Some test')
  AP.request({
    url: '/rest/api/latest/expression/eval',
    type: 'POST',
    headers: { 'Accept': 'application/json' },
    contentType: 'application/json',
    data: {
      expression: 'issue.key'
    },
    success: function (responseText) {
      console.log('Eval:', responseText)
    },
    error: function (responseText) {
      console.log('Eval error:', responseText)
    }
  })
}
</script>

</head>
<body>
  <section id="content" class="ac-content">
    <div>
      <button onclick="someTest()" target="_blank">Test</button>
    </div>
  </section>
</body>
</html>

But this does not work, the request returns this error:

Object { status: 400, statusText: “Bad Request”, responseText: “{“errorMessages”:[“Can not deserialize instance of com.atlassian.jira.rest.v2.expression.bean.JiraExpressionEvalRequestBean out of START_ARRAY token\n at [Source: com.atlassian.plugin.connect.plugin.auth.scope.InputConsumingHttpServletRequest$1@15fc521a; line: 1, column: 1]”]}”, getResponseHeader: getResponseHeader(), getAllResponseHeaders: getAllResponseHeaders() }

The only required body parameter is “expression” according to api-rest-api-2-expression-eval-post, so why it is complaining about the missing context, which BTW I am not able to provide from my panel.

Other requests works fine such as getting current user info:

AP.request({ url: '/rest/api/latest/myself', ... }) // works fine

Am I doing something wrong or is there any better approach to retrieve the current issue id?

Thank you

Hi @KahanekAles,

Perhaps you could try AP.context.getContext(). If the panel is displayed within an issue context, then the context object should contain the issue key as per the example in the linked documentation.

Regards,
Dugald

Hi @dmorrow, thank you for your reply, but this does not work either. I did exactly what is in the docs:

   function someTest () {
     console.log('Some test')
     AP.context.getContext(function(response){
       console.log("Jira Issue Key", response.issue_key);
       console.log("Confluence page id", response.pageId);
       console.log("license status", response.license);
     })
   }

And the result after button click was:

Jira Issue Key undefined
Confluence page id undefined
license status undefined

It seems that the context is not initialized.

Here is the content of my atlassian-connect.json file, if it helps (some sensitive values were replaced):

{
  "name": "TEST app",
  "description": "TEST app",
  "key": "com.some.test.jira.app",
  "scopes": [
    "read",
    "write"
  ],
  "baseUrl": "https://abdcef.ngrok.io",
  "vendor": {
    "name": "Company name",
    "url": "http://www.some-company.com"
  },
  "authentication": {
    "type": "none"
  },
  "apiVersion": 1,
  "modules": {
    "generalPages": [
      {
        "url": "/helloworld.html",
        "key": "hello-world",
        "location": "system.top.navigation.bar",
        "name": {
          "value": "Greeting"
        }
      }
    ],
    "jiraIssueContents": [
      {
        "icon": {
          "width": 0,
          "height": 0,
          "url": "/icon-24px.svg"
        },
        "target": {
          "type": "web_panel",
          "url": "/mypanel.html"
        },
        "tooltip": {
          "value": "Some tooltip"
        },
        "contentPresentConditions": [
          {
            "condition": "user_is_logged_in",
            "invert": false
          }
        ],
        "name": {
          "value": "Some name"
        },
        "key": "some-key"
      }
    ]
  }
}

Hi @dmorrow,
I have found a solution. The response contains info about current issue as folows:

{
  "jira": {
    "issue": {
      "issuetype": {
        "id": "10001"
      },
      "key": "TEST-1",
      "id": "10000"
    },
    "project": {
      "key": "TEST",
      "id": "10000"
    }
  }
}

This solves my problem now.

There is no “issue_key” field as stated in the docs.

Is the documentation outdated? Where can I find the proper information without doing endless trial and error investigation?

Thank you

1 Like