Jira addon: Create issue with JWT authorization

I’m trying to create a jira issue with a jira addon I’m developing but keep receiving ‘401 Unauthorized’ error when posting to the url. Other request I’m doing, like searching issues or getting a list of issue types work. Is there anything I’m not aware of that’s different for POST requests?

This is the request:

curl --request POST \
  --url <BASE_URL>/rest/api/2/issue \
  --header 'Accept: application/json' \
  --header 'Authorization: JWT <TOKEN>' \
  --header 'Content-Type: application/json' \
  --data <SEE BELOW>

This is the data:

{
  "fields": {
    "project": {
      "key": "TEST"
    },
    "summary": "This is a test title",
    "description": "With some description",
    "issuetype": {
      "name": "Bug"
    }
  }
}

This is the content of my JWT token:

{
  "iss": "jira.app",
  "sub": "admin",
  "qsh": "86b803b109338286ccafd963279ad7c7c8aa6b62397acb179faf24a5323b218f",
  "context": {
    "user": {
      "userKey": "admin",
      "username": "admin",
      "displayName": "Sijmen"
    }
  },
  "iat": 1525982996,
  "exp": 1525983176
}

It’s annoying that the API is only returning 401 but I’m unable to figure out why, since other request (that also require auth) are working.

Thanks in advance for your help!

Hi @sijmen,

Have you declared WRITE scope in your app descriptor (atlassian-connect.json file)?

Thanks for your quick reply. I indeed have: “scopes”: [“read”, “write”].

Does your app user have permission to create an issue in the project that you are targeting?
I’m not sure why you have a user context in your JWT token when you are making a request to Jira.

I’ve had the context in there to make sure that wasn’t the reason that it failed.

Yes the permission for creating issues is set to any logged in user.

I’m also experiencing the same issue when I try to POST to /rest/api/2/issue//remotelink

By debugging the result of createCanonicalRequest function I’ve sorted out that I hardcoded the ‘GET’ method somewhere :sweat:

Thanks for your help, it now works like charm!

1 Like