How to get attachments from Jira using Python

Jira, a sophisticated project management tool created by Atlassian, facilitates the planning, tracking, and release of software, making it a favorite among numerous software development teams. Jira also boasts features like customizable workflows, extensive reporting tools, and a potent API, all of which empower businesses to optimize their project management and boost productivity.

Given the platform’s versatility, it stores a variety of valuable data—and attachments are no exception. Getting attachments can help teams automate and streamline various processes, such as issue examination or data backups. And by leveraging the Jira API, you can programmatically fetch these files as needed.

To help you get attachments from the Jira API, we’ll cover everything you need to know. This includes setting up authentication for the Jira API and performing get requests to fetch attachments.

Authenticating with Jira

To interact with the Jira API and retrieve attachments, you need to authenticate your requests. 

Jira uses Basic Authentication, which requires you to include a header with your request. 

This header should be in the format <code class='blog_inline-code'>Authorization: Basic {Email Address}:{API-KEY}</code>. 

You can generate the Base-64 encoded string of your email address and API key, then use this string in your authorization header. In addition, your email address and API key are the credentials Jira uses to authenticate your API request. You can find your API key—which is a secure, revocable key—, within your Atlassian account.

Related: What you need to do to get projects from the Jira API

Pulling attachments from Jira

The Python code to pull attachments from the Jira API involves two steps. 

First, we need to hit the search API endpoint and paginate through the response. Second, we’ll retrieve the details of each issue and include the attachments by using the issue API endpoint.

Hit the search API endpoint

Here is the Python code that accomplishes this:

import requests
import base64
import json
# Authentication
email = "YOUR_EMAIL"
api_key = "YOUR_API_KEY"
base64_user_pass = base64.b64encode(f"{email}:{api_key}".encode()).decode()
# Pagination
offset = 0
limit = 50
has_next_page = True
# Search API Endpoint
search_url = "https://{DOMAIN}"
headers = {
    "Authorization": f"Basic {base64_user_pass}",
    "Accept": "application/json"
while has_next_page:
    query = {
        "expand": "renderedFields",
        "maxResults": limit,
        "startAt": offset
    response = requests.get(search_url, headers=headers, params=query)
    data = response.json()
    if 'issues' in data:
        for issue in data['issues']:
        has_next_page = False
    offset += limit

This script will loop through paginated issues and print each issue's ID to the console.

Hit the issue API endpoint

The next step is to get the attachments of each issue. You can do this by hitting the issue API endpoint for each issue ID:

# Issue API Endpoint
issue_url = "https://{DOMAIN}{id}"
for issue_id in issue_ids:
    response = requests.get(issue_url.format(id=issue_id), headers=headers)
    issue_data = response.json()
    if 'fields' in issue_data and 'attachment' in issue_data['fields']:
        for attachment in issue_data['fields']['attachment']:

This script will print the filename of each attachment in each issue to the console.

An example of an individual item returned by this API Endpoint is:

    "expand": "schema,names",
    "id": "10002",
    "self": "",
    "key": "PROJ-10002",
    "fields": {
        "statuscategorychangedate": "2019-07-02T12:32:49.134+0000",
        "issuetype": {
            "self": "",
            "id": "5",
            "description": "The sub-task of the issue",
            "iconUrl": "",
            "name": "Sub-task",
            "subtask": true,
            "avatarId": 10318,
            "entityId": "80ed3c99-57ff-4beb-9a24-31bdb051d650",
            "hierarchyLevel": 4
        "timespent": null,
        "project": {
            "self": "",
            "id": "10001",
            "key": "PROJ",
            "name": "Project",
            "simplified": false,
            "avatarUrls": {
                "48x48": "",
                "24x24": "",
                "16x16": "",
                "32x32": ""
            "projectTypeKey": "software"
        "fixVersions": [],
        "customfield_10018": {
            "hasEpicLinkFieldDependency": false,
            "showField": true,
            "nonEditableReason": {
                "reason": "NOT_EDITABLE",
                "message": "This field cannot be edited in the current transition."
        "customfield_10019": "Some value",
        "aggregatetimespent": null,
        "workratio": -1,
        "attachment": [
                "self": "",
                "id": "10010",
                "filename": "picture.jpg",
                "created": "2019-07-02T12:37:53.273+0000",
                "size": 23123,
                "mimeType": "image/jpeg",
                "content": "",
                "thumbnail": "",
                "author": {
                    "self": "",
                    "accountId": "557058:2baf9c2d-6aad-4b09-a0b1-df776702a9e3",
                    "avatarUrls": {
                        "48x48": "",
                        "24x24": "",
                        "16x16": "",
                        "32x32": ""
                    "displayName": "User Name",
                    "active": true,
                    "timeZone": "America/Los_Angeles",
                    "accountType": "atlassian"
        "lastViewed": "2019-07-02T12:37:57.802+0000"

Related: What you need to do to fetch comments from Jira (using Python)

Testing your Jira integration

It's a common scenario where everything seems fine during the development and testing phases, but when you go live in the production environment, unexpected issues  arise. These problems could stem from network instability, data format discrepancies, code conflicts, among other factors.

To proactively identify and address potential issues, here's what you can do:

  • Create a test plan: This plan should outline what you aim to achieve with each test, ensuring thorough coverage of all integration aspects. For example, you might include tests for user authentication or data syncing.
  • Performance testing: This step is crucial to ensure your integration can handle real-world demands. Include tests like load testing, where you simulate a high number of users, or stress testing, to see how the system performs under extreme conditions.
  • Use the right tools: Choosing the best tools can significantly enhance your testing effectiveness. Consider tools like JMeter for performance testing or SoapUI for API testing, which can provide comprehensive testing capabilities.
  • Validate JSON and XML schemas: Ensuring that your JSON and XML schemas are correct is vital for seamless data exchange. You can do this by using schema validators to check for any inconsistencies or errors in your data formats.
  • Security testing: Last but not least, security testing is paramount. This involves checking for vulnerabilities that could be exploited once the integration is live, ensuring that both your data and the system are safeguarded against potential threats.

Final thoughts

In the diverse world of ticketing systems, Jira is hardly the only player. There's a whole universe of other ticketing applications out there, such as Asana, ClickUp, and Zendesk. 

Seamlessly integrate with the ticketing systems your clients use at scale by leveraging Merge's Ticketing Unified API. You can learn more about Merge and its Ticketing Unified API by scheduling a demo with one of our integration experts.