Deepbits Platform: List all files

This API endpoint (GET /sbom_builders) allows users to retrieve a list of files uploaded to the Deepbits platform. Users must authenticate using an API key (x-api-key header) in the request headers.

Upon successful retrieval, the API returns a JSON response (200 OK) containing an array of file objects under the data field. Each file object includes details such as the file ID (_id) and file name (file_name).

Below is a demo script demonstrating how to list files on the Deepbits Platform. Adjust the placeholder with your specific API key for integration.

import requests

API_KEY = '<Your API key generated from app.deepbits.com>'
API_BASE = 'https://api.deepbits.com/api/v1'

default_headers = {"x-api-key": API_KEY }

def main():
    list_files()

def list_files():
    try:
        response = requests.get(
            f"{API_BASE}/sbom_builders",
            headers=default_headers
        )
        response.raise_for_status()  # Raise an exception for HTTP errors
        
        file_list = response.json().get('data', [])
        print("List of Files:")
        for file_info in file_list:
            print(f"File ID: {file_info.get('_id')}, File Name: {file_info.get('file_name')}")
        
        return file_list
    
    except requests.RequestException as e:
        print(f"An error occurred with the HTTP request: {e}")
        return None
    except ValueError as e:
        print(f"JSON decoding error: {e}")
        return None
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
        return None

if __name__ == "__main__":
    main()