How to Handle Complexity Budget Exhaustion When Creating Multiple Tickets Consecutively Using Monday API?

I’m facing an issue where I’m trying to create multiple tickets in Monday.com via the GraphQL API. I can successfully create 3 to 4 tickets, but after that, I receive a “Complexity budget exhausted” error (e.g., query cost 300001, budget remaining 219803 out of 1000000, reset in 9 seconds). I’ve implemented retry mechanisms with delays, but it seems like the complexity budget is still getting exhausted quickly.

Does Monday support creating multiple tickets consecutively? Is there an efficient way to batch or optimize ticket creation to avoid hitting the complexity limits? Are there any best practices to handle large-scale ticket creation or strategies to optimize API queries?

Hey @niraj83 , hope you’ve been well
Every ticket has its own complexity, and currently our API limits actions due to their complexity, so when you reach the limit - you have to retry according to the retry mechanism

Great question Niraj! There are some best practices for avoiding the complexity limit and I will share these below:

  1. Use Nested Queries: Nested queries allow you to retrieve related data in a single request, reducing the overall complexity of your operations.

  2. Add Limits to Your Queries: By limiting the amount of data returned in each query, you can reduce the complexity of your operations. This can be done by implementing pagination, using limits in your queries, and only returning required information.

  3. Avoid Making Too Many Items at the Same Time: Each create_item mutation uses 10,000 complexity points. Therefore, you should avoid creating more than 10 to 20 items in real time to prevent hitting the complexity limit. If you need to create a large number of items, you should queue your mutations.

  4. Avoid Making API Calls Concurrently: Making all mutations one after the other instead of simultaneously can help prevent data corruption on the board and reduce complexity.

  5. Use a Queuing Mechanism for Mutations and Queries: If your app has bulk mutations or queries, using a queuing mechanism can help maintain a good user experience and keep the API healthy. Some queuing service providers include BullMQ and Amazon SQS.

I do also recommend checking the complexity of your query so you can better understand the max number of tickets you are able to create at once:

mutation {
  complexity {
    query
    before
    after
  }
  create_item(board_id:1234567890, item_name:"test item") {
    id
  }
}

My experience is that creating an item is 30001 complexity - basically any item mutation is 30000+something small.