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?