Inserting relation through the API

Hi,

I am trying to insert data into a table. One of the values I would like to insert is a relation to another table.
I would like to use the row ID of the data in the other table, rather than using the display value. If I try something like this :

{
    "rows": [
        {
            "cells": [
                {
                    "column": "c-m8h7K3TEJ3",
                    "value": "Test Name "
                },
                {
                    "column": "c-fJY8WCIJFO",
                    "value": 
                       ["c-qiqWjlS4ij"]
                    
                }
            ]
        }
    ]
}

as my API insert call, I will have a broken reference in my column, as it will have tried to insert the text “c-qiqWjlS4ij” itself.

Is there any way to use IDs in insert ? I could not find anything in the documentation or the forum.

Thank you very much !
Florian.

3 Likes

Hi @Florian_Lefebvre2 - Unfortunately not. :slightly_frowning_face: At the moment the only option is to use the display value of the target row, which I understand is quite error prone. We are tracking this request internally, and I’ll bump it again.

2 Likes

This would be helpful for me too.

+1
Please add support for this! Using the display value of the target row is unreliable because there can be multiple rows with the same display name and this often requires a separate API call just to fetch the display column of a row.

+1 to this!

Bonus points if we can used the returned value of another api call as a key. E.g. “Row ID: 'i-djr7ApmsBb”’ from the UpdateRow call

1 Like

Can we please get an update on this? Can’t believe such a basic functionality is missing from the API.

Fully agree that the “real” row ID (e.g. ‘i-djr7ApmsBb’) , should be treated better by the API, including querying for rows by list of row IDs , using IDs to insert relations.
Using the display value is extremely brittle.

1 Like

Thanks for raising this issue to our attention again. I agree with you that it would be better if we supported row IDs in more places, with relation column values being the most pressing need. We don’t currently have any plans in the works to fix this, but I’m chatting with the engineering team to discuss a path forward.

5 Likes

I see this is now supported with the upsert row endpoint in the latest API update (1.4.5) - this is awesome and thank you so much for reacting to feedback so fast!

Could you please take a look at the remaining two cases:

  • Multiple row references - I tried passing both a single string (e.g. “i-KBtx1k-pJJ, i-nfq2xcBF8z”) and an array of strings (e.g. [“i-KBtx1k-pJJ”, “i-nfq2xcBF8z”]) as the cell value but neither work; the column has the Allow multiple selections option enabled
  • The update row endpoint still seems to not accept row id as cell values
2 Likes

That’s very good news, thank you for noticing @Leon_Grdic !

The update row endpoint seem to also accept row id on my side now.
But multiple row references doesn’t work too.

1 Like

Good eyes @Leon_Grdic, you beat me to it. Yes, this week we released support for passing row IDs in this upsertRows endpoint. Let me ask about the multiple row references, as I’m not sure what was intended there.

2 Likes

Also interested in this.
I guess what @Leon_Grdic is asking is instead of only being able to set one relation like :

{
  "column" : "c-fQpfvKC35x",
  "value" : "i-xxxxxxxxxx"
}

… being able to set multiple relations when the target cell is set to “allow multiple selections” with for example :

{
  "column" : "c-fQpfvKC35x",
  "value" : ["i-xxxxxxxxxx", "i-yyyyyyyyyy", "i-zzzzzzzzzz"]
}
1 Like

Yes, that’s what I understood as well. I checked with the engineering team and they hadn’t built in support for setting multiple references at once, but they are looking into that case to see if they can add support for it as well.

3 Likes

Interestingly, this isn’t working for me. Im passing my payload just as you had shown above

"body":{"rows":[
 {"cells":[
  {"column":"c-HTrCjTrep8","value":"scott"},
  {"column":"c-4BStpR6p5L","value":"scott@simpladocs.com"},
  {"column":"c-VXChNuiuRe","value":"i-CzRim0yf3_"}
 ]
}

But not working on my end, it’s simply inserting the ID itself and not the actual relation. Any idea why?

Also - Im in need of inserting multiple row references as well. . . @Eric_Koleda would love to see that addition to the API!

EDIT:

I figured it out - My relation column was not set to the correct table :sob: - but my need for inserting multiple values to a relation column via the uuid in the API still stands!

Good news! The engineer working on this has now also added support for setting multiple relations via ID using the API:

PUT https://coda.io/apis/v1/docs/{DOC_ID}/tables/{TABLE_ID}/rows/{ROW_ID}

{
  "row": {
    "cells": [
      {
        "column": "{COLUMN_ID}",
        "value": [
          "{TARGET_ROW_ID_1}",
          "{TARGET_ROW_ID_2}",
          // etc...
        ]
      }
    ]
  }
}

Let us know if you run into any issues using this.

7 Likes

Oh joy!!! Great news