👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

API Rate Limit Error and Waiting Time for Batch Deletion

5 replies
Last updated: Apr 5, 2022
Hi, I’m trying to batch delete a whole bunch of documents for a fresh start on an existing dataset; unfortunately, running into API Rate Limit error. I’m placing each mutation call in a queue per the docs. How long do I need to wait until I can try again?

ERROR: exception caught trying to delete Student: 04639232 ClientError: API rate limit exceeded
    at handler (/Users/svu/__projects/showcase/cms/node_modules/@sanity/client/lib/http/request.js:28:13)
    at applyMiddleware (/Users/svu/__projects/showcase/cms/node_modules/@sanity/client/node_modules/get-it/src/util/middlewareReducer.js:8:15)
    at onResponse (/Users/svu/__projects/showcase/cms/node_modules/@sanity/client/node_modules/get-it/src/index.js:90:22)
    at cb (/Users/svu/__projects/showcase/cms/node_modules/@sanity/client/node_modules/get-it/src/index.js:57:55)
    at callback (/Users/svu/__projects/showcase/cms/node_modules/@sanity/client/node_modules/get-it/src/request/node-request.js:53:46)
    at /Users/svu/__projects/showcase/cms/node_modules/@sanity/client/node_modules/get-it/src/request/node-request.js:146:14
    at DestroyableTransform.<anonymous> (/Users/svu/__projects/showcase/cms/node_modules/simple-concat/index.js:8:13)
    at Object.onceWrapper (events.js:421:28)
    at DestroyableTransform.emit (events.js:327:22)
    at endReadableNT (/Users/svu/__projects/showcase/cms/node_modules/readable-stream/lib/_stream_readable.js:1010:12) {
  response: {
    body: { message: 'API rate limit exceeded' },
    url: '<https://uvdp4b76.api.sanity.io/v2022-03-26/data/mutate/showcase-spr-2022?returnIds=true&returnDocuments=true&visibility=sync>',
    method: 'POST',
    headers: {
      date: 'Thu, 31 Mar 2022 20:07:00 GMT',
      'content-type': 'application/json; charset=utf-8',
      'x-ratelimit-remaining-second': '0',
      'retry-after': '1',
      'ratelimit-reset': '1',
      'x-ratelimit-limit-second': '50',
      'ratelimit-remaining': '0',
      'ratelimit-limit': '50',
      'content-length': '41',
      vary: 'Origin',
      via: '1.1 google',
      'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
      connection: 'close'
    },
    statusCode: 429,
    statusMessage: 'Too Many Requests'
  },
  statusCode: 429,
  responseBody: '{\n  "message": "API rate limit exceeded"\n}'
}
Mar 31, 2022, 8:14 PM
Hi Steve. Api limits cab be found here https://www.sanity.io/docs/technical-limits#50838b4c19db
Mar 31, 2022, 9:57 PM
Thanks
user P
… if the API rate limit is exceeded, is there a time range we have to wait until submitting the batch of requests?
Apr 1, 2022, 5:27 PM
We count it by a rolling window, so it depends on how many you trigger simultaneously
Apr 3, 2022, 6:52 PM
Hi
user P
/
user A
, thanks for following up. I did after some trial and errors. I added some improvements to my data clean up script will test again on the next new project.
Apr 5, 2022, 5:46 AM
Hi
user P
/
user A
, thanks for following up. I did after some trial and errors. I added some improvements to my data clean up script will test again on the next new project.
Apr 5, 2022, 5:46 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?