Deepbits Platform: List linked files of a project

This script demonstrates how to list all files linked to a specific project on the Deepbits platform using the GET /project/{project_id}/assets API endpoint.

Users must authenticate using an API key (x-api-key header) in the request headers. Upon a successful request, the API returns a JSON response containing the list of file IDs linked to the specified project under the data field.

Below is a demo script demonstrating how to list all linked files of a project. Adjust the placeholders and with your specific values for integration.

import requests
import time
import json

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 }

PROJECT_ID = '<Your Project ID>'

def main():
    response = get_file_id_list_by_project_id(PROJECT_ID)

    if response:
        print(f"File ID list: {response}")
    else:
        print("Failed to get file ID list")

def get_file_id_list_by_project_id(project_id):
    try:
        resp = requests.get(f"{API_BASE}/project/{project_id}/assets", headers=default_headers)
        resp.raise_for_status()
        data = resp.json().get('data', {})
        docs = data.get('docs', [])
        if docs:
            return docs[0].get('assetIds', [])
        else:
            return []
    except (requests.RequestException, ValueError, KeyError) as err:
        print(f"An error occurred: {err}")
        print(resp.text)
        return []

if __name__ == "__main__":
    main()