How to fetch all project versions in Jira using Python and REST API?

Hey folks, I need some help with the Jira REST API. I used to use JIRA.project_versions(id) to get all the releases for a project. Now I’m switching to the requests library and I’m a bit lost.

I’ve got this working for fetching issues:

response = requests.get(
    'https://example.atlassian.net/rest/api/2/search',
    headers={'Accept': 'application/json'},
    params={'jql': 'project=MyProject', 'startAt': 0, 'maxResults': 0},
    auth=(username, api_token)
)

This gives me the total count. Then I can change startAt and maxResults to grab all the issues in chunks.

But I can’t figure out how to do the same for project versions (releases). Any ideas on the right endpoint or params to use? Thanks in advance!

For fetching project versions in Jira using the REST API, you’ll want to use the ‘/rest/api/2/project/{projectIdOrKey}/versions’ endpoint. Here’s a Python snippet that should work:

import requests

url = f'https://your-domain.atlassian.net/rest/api/2/project/{project_key}/versions'
response = requests.get(url, auth=(username, api_token))

if response.status_code == 200:
    versions = response.json()
    for version in versions:
        print(f"Version: {version['name']}, ID: {version['id']}")
else:
    print(f"Error: {response.status_code}, {response.text}")

This will fetch all versions for the specified project. If you have a large number of versions, you might need to implement pagination by adding ‘startAt’ and ‘maxResults’ parameters to your request. The response includes useful metadata about each version, such as release dates and descriptions.

hey ethan, for project versions try this endpoint:

‘/rest/api/2/project/{projectIdOrKey}/versions’

replace {projectIdOrKey} with ur project’s ID or key. no need for params, it’ll fetch all versions. if u need pagination, add ‘startAt’ and ‘maxResults’ params like u did for issues.

hope this helps! lemme kno if u need anything else

I’ve been in your shoes, Ethan. Switching from the JIRA library to raw REST API calls can be tricky. Here’s what worked for me:

url = f'https://your-domain.atlassian.net/rest/api/2/project/{project_key}/version'
response = requests.get(url, auth=(username, api_token))
versions = response.json()

This fetches all versions for the project. If you have many versions, you might want to add pagination:

params = {'startAt': 0, 'maxResults': 50}
response = requests.get(url, auth=(username, api_token), params=params)

You can then iterate through the results, increasing ‘startAt’ until you’ve fetched all versions. Remember to handle rate limits and potential errors in your code. Good luck with your implementation!