I'm getting "No project could be found with key 'ABC'." even though GET .../project/ABC works

Malte Finsterwalder September 18, 2020

I'm trying to create a Jira component via the REST API.

I POST to https://my.atlassian.net/rest/api/3/component

In the POST request body I set:

{
"name": "Component 1",
"description": "This is a Jira component",
"project": "ABC",
"assigneeType": "UNASSIGNED",
"leadAccountId": "myaccountid"
}

A project with key ABC exists. And when I GET https://my.atlassian.net/rest/api/3/project/ABC
I get a proper response with:

"key" : "ABC"

So it's there and I have access to it.

But when I send the POST to create the component I always get a 404 back with:

{ "errorMessages": [ "No project could be found with key 'ABC'." ], "errors": {}}

And ideas, why this is happening?

I'm using Postman with an API Token. The user is a Jira Admin.

1 answer

0 votes
Rudy Holtkamp
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 18, 2020

Hi @Malte Finsterwalder ,

I just created a component on my own instance via Postman. And there is no problem at all.

A 404 is returned if the project is not found or the user does not have permission to browse the project containing the component.

So the first is not the case, it should be the latter. Or it might be that Jira Admin is not a project admin and can't create components.

Rudy

Malte Finsterwalder September 18, 2020

Thanks for trying that!

When I'm logged in with the same user in Jira, I can see the project and I can create a component.

When I do it through the rest API I can also see the project with all it's details, as described above. So I obviously have permissions to access the project.

In "Project settings"->"People" the group "jira-administrators" is present as Role "Administrators" and I'm part of that group.

I also added myself to the Project with Role "Administrators" but that still does not work.

Hm....

Malte Finsterwalder September 18, 2020

I can create a new project via REST API, but I still can't create a component in that new Project. I'm also the lead of that new project.

I still get "No project could be found with Key 'NEW'."

Rudy Holtkamp
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 18, 2020

Is it a classic project or a next gen?

I've used a classic project.

Malte Finsterwalder September 21, 2020

It's a classic project as well.

Rudy Holtkamp
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 21, 2020

In that case...I've no idea left. Sorry.

I think you should contact Atlassian support to get this one sorted out. I do stay curious about what is the problem, so if they have figured it out, could you please report it here?

Malte Finsterwalder September 21, 2020

Thanks for all your help! If I find the problem, I will post the solution here.

Like Rudy Holtkamp likes this
Peter Blom December 2, 2020

Hi @Malte Finsterwalder , Hope you've found the solution :) I'm running into the same challenge. When I open the URL directly in my browser when logged-in, all works well. But when running the same API GET in automations I get the issue:

"errorMessages": [
    "No project could be found with key 'XXX'."
Like Luca Calderone likes this
Peter Blom December 2, 2020

Hi @Malte Finsterwalder and others with this issue. I found the solution! I had to add a header with an API key to allow access to the webservice that is hashed in base64 together with my email. (emailaddress:apikey)

Anuj Patel December 26, 2021

could you please share the example.

Malte Finsterwalder January 2, 2022

I eventually programmed this in Python. The core problem was authentication with username and API Key.

Here is a short Python example, that works for me:

import requests

apiKey = os.environ['JIRA_API_KEY'] # fetch the Jira API Key from an env variable
a = ('<my login email>', apiKey) # create a pair with username and API Key
jsonResp = requests.get('....', auth=a).json() # pass login data as auth parameter
jsonResp = requests.post('....', auth=a).json() # pass login data as auth parameter
...

Like Luca Calderone likes this
Piotr Poliwoda July 21, 2022

So how would this look like in a node version? I'm getting the same 404 error and I've tried multiple ways of adding the Bearer token, none of which seem to work, but they do authenticate properly because if I put a random character in the token it tells me it's unauthorised then.

Neither

  'Authorization': `Bearer ${

Buffer.from(JIRA_API_EMAIL + ':' + JIRA_API_TOKEN).toString('base64');
}`,
NOR 

  'Authorization': `Bearer ${

JIRA_API_EMAIL + ':' + JIRA_API_TOKEN
}`,
seem to work but they do authenticate correctly with Jira's API (?)
Rudy Holtkamp
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 21, 2022

Try 'Basic' instead of 'Bearer'

Piotr Poliwoda July 21, 2022

I had Basic at the beginning, I was getting an error saying something along the lines of user and password authentication is depricated, so I tried the Bearer. 

Edit: actuallly, here it is:
Response: 401 Unauthorized
Basic authentication with passwords is deprecated. For more information, see: https://developer.atlassian.com/cloud/confluence/deprecation-notice-basic-auth/

Piotr Poliwoda July 21, 2022

OK, I eventually got it working with the basic token. Stupid to admit it now, my environment variables weren't exported with export TOKEN=asd in my .bashrc, rather just set as TOKEN=asd ... 

A token that was being passed was there but it was a tad short.. 

So the working end result was in fact:

const authenticationBuffer = Buffer.from(`${JIRA_API_EMAIL}:${JIRA_API_TOKEN}`).toString('base64');

  fetch('https://zoovu.atlassian.net/rest/api/2/myself', {

    method: 'GET',

    headers: {

      'Authorization': `Basic ${authenticationBuffer}`,

      'Accept': 'application/json',

    }

  })

    .then(response => {

      // eslint-disable-next-line no-console

      console.log(

        `Response: ${response.status} ${response.statusText}`

      );

      return response.text();

    })

    // eslint-disable-next-line no-console

    .then(text => console.log(text))

    // eslint-disable-next-line no-console

    .catch(err => console.error(err));

}
after all. Thanks all. And hope others find this useful.
Like Rudy Holtkamp likes this

Suggest an answer

Log in or Sign up to answer