Unable to get linked records (base.get_linked_records)

Problem

A Python script. Although I have table_id, link_column_key, and rows which are required for base.get_linked_records() as described in Links - SeaTable Developer Manual, I am getting an error. The code has the fetched values as comment for you to check if they’ve got the right format, and you can also find the error message as final comment. I’ve also attached a screenshot which proves there is a linked record in the ‘master’ column.

I’ve also tried to use table and column names instead of keys, but this seems only to be possible in the API. I’ve also tried to omit the rows= explicit parameter name in front of simply providing the JSON-ish list of rows (which is a one-list in my case).

Script With Error Message As Comment

from seatable_api import Base, context

base = Base(context.api_token, context.server_url)
base.auth()

lang_table = context.current_table
metadata = base.get_metadata()

lang_table_id = next((table['_id'] for table in metadata['tables'] if table['name'] == lang_table), None)
link_column_key = base.get_column_link_id(lang_table, 'master')
lang_row_id = context.current_row['_id']
rows_list = [{'row_id': lang_row_id}]

debug_lang_keys = (
    f"lang_table_id: {lang_table_id}, \n"      # 2j7j
    f"link_column_key: {link_column_key}, \n"  # j6jR
    f"lang_row_id: {lang_row_id}, \n"          # ZYuI7cT7T6iYOwPkLMePKA
    f"rows_list: {rows_list}, \n"              # [{'row_id': 'ZYuI7cT7T6iYOwPkLMePKA'}]
)

try:
    json = base.get_linked_records(lang_table_id, link_column_key, rows=rows_list)
    debug_lang = f'SUCCESS: \n\n{debug_lang_keys}json: {json}'
except Exception as e:
    debug_lang = f'ERROR: Failed to fetch linked records.\n\n{debug_lang_keys}\n Exception: {str(e)}'

lang_row_data = {'debug': debug_lang}
base.update_row(lang_table, lang_row_id, lang_row_data)

# Exception: [Errno 400] {"error_message":"failed to get column for table: 2j7j, 
# name: [],key: [j6jR] in base 31994138-1ca3-48cf-a094-3871012c0053: column not exists"}

Maybe a related issue which hasnt’t been answered yet: Note able to recover again columns with more than 10 elements in a row

Hi,
The error might be caused by link_column_key = base.get_column_link_id(lang_table, 'master') which returned is link_id of link_column instead of column_key. The code can be modified like below

...
lang_table = next((table for table in metadata['tables'] if table['name'] == lang_table), None)
lang_table_id = lang_table['_id']
link_column = None
for col in lang_table['columns']:
   if col['name'] == 'xxxxx':
       link_column = col
       break

link_column_key = link_column['key']
.....

Please try it again, and this might solve the problem

@fritzfeger Can we close the issue?