Using REST API returns "Internal server error"

George Portillo December 1, 2023

I know you've answered this before but I have done it all.

 

I've set the right permissions in the project settings. To public as a matter of fact because nothing else worked for my app. Both for:

- Creating issues

- Managing reporters

 

I also had to manually find my userId so I could use it as a valid reporter id.

 

I have literally copied your example's code, and included the bare minimum JSON to create a Jira issue, all from your documentation:


```

const bodyData = {
"fields": {
  "description": {
    "content": [
      {
        "content": [
          {
            "text": "Order entry fails when selecting supplier.",
            "type": "text"
          }
        ],
        "type": "paragraph"
      }
    ],
    "type": "doc",
    "version": 1
  },
  "issuetype": {
  "name": "Bug"
},
"project": {
  "key": "FEED"
},
"reporter": {
  "id": "712020:6900724a-9c98-430b-b911-f414478232f0"
},
  "summary": "Main order flow broken"
},
"update": {}
};

console.log('`${email}:${token}`', `${email}:${token}`);

const response = await fetch('https://chainfuse.atlassian.net/rest/api/3/issue', {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${Buffer.from(`${email}:${token}`).toString('base64')}`,
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(bodyData),
});```

Even after passing every other error that complained about missing data (such as invalid reporter id, or invalid issueType, or invalid project, it just gives me a generic, unhelpful error.
I've gone through all of the similar issues, and I even looked at this unhelpful article from Confluence: https://confluence.atlassian.com/jirakb/get-an-internal-server-error-message-when-trying-to-create-a-new-issue-through-rest-method-771989931.html
I still don't know why my REST create issue query is failing. Please help me understand what I'm doing wrong. I've spent hours on this issue already. I wish the error code was actually helpful.

2 answers

0 votes
George Portillo December 1, 2023

...

0 votes
Jeroen Poismans
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 1, 2023

Hi and welcome to the Atlassian community!

Try taking a step back, away from the code ... Use a tool like Postman to do the exact call as described and see if you can get that to work. This way you know your JSON, auth method (API token ...) is correct. From there you can move on and put it in your code.

This are probably the docs that you have used:
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-post

This works.

See how far you get with this!

George Portillo December 1, 2023

Thank you for the swift reply Jeroen.

 

Here's my output, same thing:

Screenshot 2023-12-01 at 9.37.04 AM.png

I'm using basic auth, putting my email as the username, and the access_token I received after going through the authentication flow I enabled using my Atlassian's OAuth 2.0 App.

 

Any ideas?

Jeroen Poismans
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 1, 2023

In your screenshot you are missing a closing "}" at the end.

George Portillo December 1, 2023

I copy pasted my JSON into a linter and it said the JSON is valid.

I double checked and I have no missing "}". Unfortunately.

Screenshot 2023-12-01 at 10.02.07 AM.png

Jeroen Poismans
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 1, 2023

I was mislead by the indentation, my bad.

I have done the exact same call (reporter my own id, own project):

Screenshot 2023-12-01 at 19.11.31.png

The api seems to work perfectly, issues are created so something in the content makes the call fail in your case. One or some of the fields aren't on the create screen of the issuetype in that project, accept and content-type headers ...).

That's about the only thing I can think of because the call works here. Fact that it didn't work in the app, that could have several reasons. Call not working via Postman, then you will have to look at setup again. Try another (test) project?

Regards!

George Portillo December 1, 2023

I created a brand new Company-managed project, and now I am setting the permissions.

 

I am using an access token that I got from oauth with the  following scopes:

read:account read:me write:jira-work

 

And I have also set the following permissions to public (because I'm not sure how to grant my oauth app these permissions):


Screenshot 2023-12-01 at 10.28.32 AM.png


Screenshot 2023-12-01 at 10.31.08 AM.png


These are the only two permissions I've set, and it's still throwing me the same error.

Could it be something in my screens?

Screenshot 2023-12-01 at 10.34.05 AM.png

I appreciate you taking the time to help me with this Jeroen.

George Portillo December 1, 2023

I'm also on a 14 day trial, could that be causing issues?

Jeroen Poismans
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 1, 2023

The Create screen for the project and issue type should contain all the fields you are trying to set in the call. 

Furthermore, try creating an api token to use in you call:
https://id.atlassian.com/manage-profile/security/api-tokens

In Postman user basic auth with you emailadres and the token as password.

George Portillo December 1, 2023

Using the API token I generated worked, which is great but why didn't my oauth access token work?

My current app's flow is authenticating the user via oauth, and then trying to perform the operation (creating an issue) on the project they choose from a dropdown.

Does that mean that in order to enable at-scale usage of the Jira API for an org in our platform, we'll have to either:

1- Use one API key to handle all the operations for an org

2- Ask everyone to provide their ownAPI key

3- Can a managed account be used in this instance?

Trying to understand how I can enable this flow at scale, or at least what's industry standard.

What do you recommend?

Again, thank you for all the help Jeroen

Jeroen Poismans
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 1, 2023

Ok, so that is cleared out.

The problem is then with you oAuth implementation in your app. Probably something wrong there, but since this now has become more of an implementation issue in an app instead of a configuration issue in the product, I think you will get a better answer concerning this and how to implement oAuth in your app in the Atlassian Develop Community:

https://community.developer.atlassian.com/

Good luck!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events