Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document 10 recor limits of batch create calls withtable.create() #172

Open
madebycaliper opened this issue May 28, 2020 · 0 comments
Open

Comments

@madebycaliper
Copy link

I've built an online store/shopping cart system with Airtable. Generally, I'm a huge lover and evangelist of Airtable.

That said, I just spent the better part of two days trying to figure out why some of my user's Orders were not going through. The culprit: when orders with more than 10 items were created, it was triggeriung a 422 response from a call to base(TABLE_NAME).create(orderItems).

After seeing this function referenced in the Interactive API in my account, I found the source from digging through the code in this repo (this project is severely lacking in documentation – see #93 ) and I didn't see anything that made me think it would error out with more than X records. I was also unable to find any example of how to use a recursive callback of some sort. This function just 422's and doesn't return "remaining" records or anything.

The solution I came up with uses Axios.all() to allow for a true "batch" create using async/await:

  const TABLE_NAME = 'Order Items'

  async batchCreate(cartItems) {
    let chunkSize = 10
    let chunkedCreateCalls = []
    // Split requests into 10 records at a time
    for (let i = 0, j = cartItems.length; i < j; i += chunkSize) {
      chunkedCreateCalls.push(
        base(TABLE_NAME).create(cartItems.slice(i, i + chunkSize))
      )
    }
    try {
      let newItems = await Axios.all(chunkedCreateCalls)
      return newItems || []
    } catch (error) {
      return Error(error)
    }
  }

I hope this can help someone else avoid the headache of troubleshooting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant