1

I'm using jira-python to access jira projects. I'm trying to pass a numeric key (which is not the project id) as a parameter.

myProject = jira.project("100")

However, I get the following error:

response text = {"errorMessages":["No project could be found with id '100'."],"errors":{}}

I'm not trying to pass an id, so is there a way to differentiate between a numeric key and an id.

I was doing some testing and it seems like an alphanumeric key is accepted e.g. key = Test1

ghostwar 88
  • 547
  • 1
  • 6
  • 17
  • 1
    By default, JIRA issue keys (aka Issue IDs) are of the format -, eg. ABC-123. You can get all project keys that were created in your Jira instance from `/rest/api/2/project/?expand=projectKeys` – amuratova Apr 07 '20 at 14:58
  • 1
    @amuratova I'm not talking about issues keys. I was talking about **project** keys, and how my project keys are numeric, so the function call thinks they are project ids and not project keys. – ghostwar 88 Apr 07 '20 at 22:10
  • 1
    thank you for clarification. To be sure that project exists, have you tried to pass project id instead of project key? – amuratova Apr 08 '20 at 14:19

2 Answers2

2

According to Jira Rest API documentation, Jira client always expects to receive a projectIdOrKey parameter as string. And it seems so, that the only way for it to determine, whether a Project Key or a Project ID was passed, is to check whether a string is numeric or not. That would mean that there is no way for Jira to recognise that you are using a Project Key instead of a Project ID, if you are passing a numerical value.

I checked that the source code of Jira API client in Python does indeed convert any input into string. Unfortunately, I can't check whether Jira API server indeed decides on whether it received an ID or a key in a way I suppose it does because it is not open source.

If my hypothesis is correct, then the only solution would seem to be not to use numerical values as project keys, instead always using a key that contains letters as well.

amuratova
  • 421
  • 3
  • 9
  • 1
    Yeah thought so. I even tried `val = 100\n myProject = jira.project(val.toString())` and even that didn't work. – ghostwar 88 Apr 12 '20 at 23:06
0

You could not create a project in Jira with the key beginning with the number. Project keys must start with an uppercase letter, followed by one or more uppercase alphanumeric characters.

https://support.atlassian.com/jira-work-management/docs/work-with-issues-in-jira-cloud/#Workingwithissues-Projectkeys

Project admins can create and assign their project's key when they create a new project. Based on the project's name, Jira suggests a recognizable key. If you're a project admin, you can customize this while creating a project by selecting Advanced options. You can also update it in the project's settings. They must be at least 2 characters long and start with an uppercase letter. Read more about editing a project's details.