Export Full Document Map (including formulas)


Does anyone know if it’s possible to export the document map, including formulas?

I would like to be able to copy/paste my entire doc “codebase” (mostly in order to debug/brainstorm with ChatGPT).

I know that it’s possible to export most of the Document Map with a python script via the API, but it doesn’t appear as though the API supports retrieving column formulas.



Ok, so it looks like because of Pack architecture, there’s no way to create a Pack that exports the full Doc Map. But it is very possible using the API via a Python script.

The following script exports all the buttons and pages in your doc, then nests the tables within each page and the columns within each table, including the name, format, and FORMULA of each column.

The only thing it looks like we can’t do using the API is display the formulas in buttons.

If you’re using this, be sure to specify your Doc ID and API token

import requests

#RW document details

# Define headers globally
headers = {
    'Authorization': f'Bearer {API_TOKEN}',
    'Content-Type': 'application/json',

def make_api_request(url, headers):
    Make an API request and return the JSON response.
        response = requests.get(url, headers=headers)
        response.raise_for_status()  # Raises a HTTPError for bad responses
        return response.json()
    except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")
        return None

def fetch_controls(doc_id):
    Fetch controls (including buttons) for a Coda document.
    url = f'https://coda.io/apis/v1/docs/{doc_id}/controls'
    response_json = make_api_request(url, headers)
    return response_json.get('items', []) if response_json else None

# Fetch and display controls at the beginning
controls = fetch_controls(DOC_ID)
if controls:
    print("Controls in the document:")
    for control in controls:
        print(f"- Control Name: {control['name']}, Type: {control['type']}")
    print("No controls found in this document.")

def list_pages(doc_id):
    List all pages in a specified Coda document.
    headers = {'Authorization': f'Bearer {API_TOKEN}', 'Content-Type': 'application/json'}
    url = f'https://coda.io/apis/v1/docs/{doc_id}/pages'
    response_json = make_api_request(url, headers)
    return response_json.get('items', []) if response_json else None

def list_tables(doc_id):
    List all tables in a specified Coda document.
    headers = {'Authorization': f'Bearer {API_TOKEN}', 'Content-Type': 'application/json'}
    url = f'https://coda.io/apis/v1/docs/{doc_id}/tables'
    response_json = make_api_request(url, headers)
    return response_json.get('items', []) if response_json else None

def list_columns(doc_id, table_id):
    List all columns in a specified table in a Coda document and include detailed information based on conditions.
    headers = {'Authorization': f'Bearer {API_TOKEN}', 'Content-Type': 'application/json'}
    url = f'https://coda.io/apis/v1/docs/{doc_id}/tables/{table_id}/columns'
    response_json = make_api_request(url, headers)
    if not response_json:
        return None
    columns = []
    for item in response_json.get('items', []):
        column_info = {
            "name": item.get("name"),
            "parent": item.get("parent", {}).get("id"),
            "format": item.get("format")
        if item.get("display"):
            column_info["display"] = item.get("display")
        if item.get("calculated"):
            column_info["calculated"] = item.get("calculated")
        if item.get("formula") not in [None, "No formula set"]:
            column_info["formula"] = item.get("formula")
        if item.get("defaultValue") not in [None, "No default value"]:
            column_info["defaultValue"] = item.get("defaultValue")
    return columns

# Retrieve and process pages, tables, and columns
pages = list_pages(DOC_ID)
tables = list_tables(DOC_ID)

if pages and tables:
    for page in pages:
        print(f"\nPage Name: {page['name']}, Page ID: {page['id']}")
        page_tables = [table for table in tables if 'parent' in table and table['parent']['id'] == page['id']]
        if page_tables:
            print("Tables on this page:")
            for table in page_tables:
                print(f"  Table Name: {table['name']}, Table ID: {table['id']}")
                columns = list_columns(DOC_ID, table['id'])
                if columns:
                    print("    Columns in this table:")
                    for column in columns:
                        column_details = f"      Column Name: {column['name']}"
                        column_details += f", Format: {column['format']}"
                        if "display" in column:
                            column_details += ", Display: True"
                        if "calculated" in column:
                            column_details += ", Calculated: True"
                        if "formula" in column:
                            column_details += f", Formula: {column['formula']}"
                        if "defaultValue" in column:
                            column_details += f", Default Value: {column['defaultValue']}"
                    print("    No columns found in this table.")
            print("No tables on this page.")
    print("No pages or tables found or there was an error fetching the data.")

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.