Apologies for the delay here - but amazing job figuring it out! Giving those calls a bit of breathing room so they can be made consecutively should do the trick - but if you run into any other issues please let us know
Take my suggestion with a grain of salt especially since you’ve already got it, but I still want to throw it out there just in case it’s useful.
I think you should take advantage of the async / await you already have. I did it locally and everything still works.
So instead of using setTimeout, you can use:
this.state.columnTitles.forEach(async col => {
await this.createColumn(boardId, col.title, col.type)
})
Hey @pepperaddict - thanks for jumping in here and sharing a different way to approach this, that’s awesome!
@supernova what I think is happening here is you are hitting the complexity rate per minute cap of our API when making those calls, which is why the setTimeout solution works as well. By adding a delay between the calls, the queries are more spread out and they are less likely to hit the limit. Does that make sense?
I hope that helps get this to work in the most efficient way possible
Thank you for clarifying further! I think the async/await doesn’t work in this case because the calls are still running too close to each other - either way, I’m glad that adding timeouts would work for your use case.
But I’m confused cause it worked for …
Please confirm @pepperaddict? cause async/await is obv the cleaner solution if I could only get that to work instead
I only counted for the console log as the success and jumped at that, but when previewing my actual Monday app, the columns didn’t show. Bummer. Sorry about that!
So, I tried a different method. I think the problem more aligns with forEach() as it fires them all at once and instead of a one-at-a-time thing which is what we want. I tried a for loop and that works. haha. I tested it twice and have seen the three columns show each of those times. Before that, I’ve tried .map() with Promise.all and that didn’t work. columnTitles.reduce() didn’t work either… but a generic for loop does.
const boardId = data.data.create_board.id
for (const col of columnTitles) {
await createColumn(boardId, col.title, col.type)
}
If that doesn’t work, it may be because of the other stuff I added with it. My code is in functional component so it’s a bit different than your class components.
Ahh ok np I see, yup in this case the log in console is misleading. That’s why I created this thread haha I also tried it before with Promise.all & .map ( sorry for making you repeat the same mistakes I did ) - should’ve been clearer in my initial post as it seems like it’s stirred up quite a bit of confusion here!
Interesting that a simple for loop does the trick…I haven’t tested it yet but I’ll take your word for it I appreciate the time you took to follow up & recreate this on your end Thanks @pepperaddict <3