Cannot find Row ID of Row just added through API

I am successfully calling into the Coda API to insert a row. I’ll get this response which shows the row ID:

{
  requestId: 'mutate:c39bd6d9-2719-40e4-bd21-110f3c520031',
  addedRowIds: [ 'i-ECC1p8uxHE' ]
}

However, if I then call into the API to get the detail of that row (so I can get the browserLink), it is returning a completely different row ID. If I make successive calls, it will then give me the correct Row ID I expect from the last invocation. So it’s as if the API is returning stale data.

E.g. Notice the above Row ID is i-ECC1p8uxHE. If I try to get a row with that ID, the API throws an error. If I list the rows in the table, it’ll spit this out (notice the row ID of i-PlTbFAngZp'.

{
  items: [
    {
      id: 'i-PlTbFAngZp',
      type: 'row',
      href: 'https://coda.io/apis/v1/docs/9VWSYn80-C/tables/grid-TpiES2KaX-/rows/i-PlTbFAngZp',
      index: 0,
      createdAt: '2022-02-20T21:30:43.199Z',
      updatedAt: '2022-02-20T21:30:43.199Z',
      browserLink: 'https://coda.io/d/_d9VWSYn80-C#_tugrid-TpiES2KaX-/_rui-PlTbFAngZp',
      values: [Object]
    }

If run my script again, the insertion happens again, and it spits out a new row ID (which I’d expect since it’s a brand new insert) but the list of rows will then be i-ECC1p8uxHE which is the PREVIOUS row inserted.

I’m certain it’s a race condition issue, and something with my code. But I need some tips on how to do this:

var codaRowUri;
const resp = await require("@pipedreamhq/platform").axios(this, {
  method: 'POST',
  url: `https://coda.io/apis/v1/docs/${docId}/tables/${tableId}/rows`,
  headers: axiosHeaders,
  data: data
})
.then( (response) => {
  console.log(response);
  codaRowUri = `https://coda.io/apis/v1/docs/${docId}/tables/${tableId}/rows/${response.addedRowIds[0]}`;
})
.catch( (error) => {
    console.log("Error adding row to Coda");
    console.log(error);
});

console.log(`codaRowUri: ${codaRowUri}`);

// Try to get the URL to the row ID
return await require("@pipedreamhq/platform").axios(this, {
  method: 'GET',
  url: codaRowUri,
  headers: axiosHeaders
});

What do I need to change?

I’m not able to reproduce the changing row ID, but I did notice that the newly added row isn’t immediately available via the API. The documentation says that is to be expected:

Row inserts/upserts are generally processed within several seconds.

That said, if all you need is the browser link you can construct it yourself from the row ID:

https://coda.io/d/_d{DOC_ID}#_tu{TABLE_ID}/_ru{ROW_ID}

Yeah I saw that mention but I’m even adding a sleep of 10 seconds on my code. I see the row getting added to the doc (i have it loaded in another window). After the 10s sleep, the API still return false.

Your solution is way simpler to construct the link. Thank you! I was looking for the syntax but didn’t see it.

Ya, it’s added to the doc long before it’s available via the API, due to how the API functions. I don’t think that row link pattern is officially documented, but it’s been discovered by the community and not likely to change.

I’m close, this works! I’d love to pop up the modal to the entry, but it doesn’t look like it’s working for me to add ?modal=true or &modal=true. Any tips?

Appending &modal=true worked for me.

Interesting… I can’t get to work.

doc ID = 9VWSYn80-C
table ID = grid-TpiES2KaX-
row ID = i-7P7aJIvZ5W

URL:
https://coda.io/d/_d9VWSYn80-C#_tugrid-TpiES2KaX-/_rui-7P7aJIvZ5W

I then added &modal=true:
https://coda.io/d/_d9VWSYn80-C#_tugrid-TpiES2KaX-/_rui-7P7aJIvZ5W&modal=true

but it doesn’t work…

Update: &view=modal worked!

eg.
https://coda.io/d/_d9VWSYn80-C#_tugrid-TpiES2KaX-/_rui-7P7aJIvZ5W&view=modal

I get the missing row via API as well, but typically only If nothing has been entered yet. If I fill out one row field then it seems to find it in the API.