Skip to main content

How I could delete multiple items in one API call?

  • October 28, 2023
  • 7 replies
  • 572 views

I want to delete multiple items in one API call, something like the following:

mutation{
delete_item(item_id: 5406008582) {
id
}
delete_item(item_id: 5406008601) {
id
}
}

7 replies

  • Participating Frequently
  • October 28, 2023

You need to use multiple named mutations (instead of anonymous mutations) in the same request:

mutation delete1 {
  delete_item(item_id: "12321321") {
    id
  }
}

mutation delete2 {
  delete_item(item_id: "5242344") {
    id
  }
}

Notice how each mutation has a name (delete1, delete2) now? this allows multiple mutations in the same request.


  • Author
  • Participating Frequently
  • October 28, 2023

Thanks @anon29275264. It worked.


  • Participating Frequently
  • October 28, 2023

A few things to watch:

Since the API server has a limit of 5000 connections per IP per minute:

If this is a UI based feature, it may be preferable to just do two queries, and use Promise.allSettled() to execute concurrently but handle them individually.

If you’re using a microservice backend, I would do the same since the IP space your microservices run in is much larger. You won’t run into limits by having concurrent connections.

If you’re using a monolithic server (container or VM) that is serving many accounts simultaneously, from a single IP, then using GraphQL batching as shown may be a way avoid exhausting the 5000 cpm rate limit in a busy environment.

The problem with batching the mutations into a single call, is with error handling and retrying since you now must parse responses, figure out which ones failed, and retry them as appropriate. This particularly comes in with API complexity limits. Individual requests will error individually and you don’t need to write code just to figure out what failed - you already know.


  • Author
  • Participating Frequently
  • October 29, 2023

@anon29275264
The code you have shared is working fine when I execute it on https://monday.com/developers/v2/try-it-yourself, but when I convert it to Python it no longer works.

query = '''
mutation delete1($item_id_1: Int!) {
        delete_item(item_id: $item_id_1) {
                id
        }
}

mutation delete2($item_id_2: Int!) {
        delete_item(item_id: $item_id_2) {
                id
        }
}
'''
variables = {'item_id_1': 5406008, 'item_id_2': 548754}
data = {'query' : query, 'variables' : variables}
response = requests.post(url=apiUrl, json=data, headers=headers) # make request
response.json()

The code above give me the following error:

{'errors': [{'message': 'An operation name is required'}], 'account_id': 196}

The query you shared works fine on https://monday.com/developers/v2/try-it-yourself but the exact same query in Python give me the same error I shared above.


Matias.Monday
Forum|alt.badge.img
  • monday.com Team Member
  • October 29, 2023

Hello there @AmirSaleem,

Can you please try something like this?

mutation($item_id_1: Int!, $item_id_2: Int!){ 
    delete1: delete_item(item_id: $item_id_1) {id}

    delete2: delete_item(item_id: $item_id_2) {id}
}

Let me know how that goes!

Cheers,
Matias


  • Author
  • Participating Frequently
  • October 30, 2023

It worked. Thanks @Matias.Monday


Matias.Monday
Forum|alt.badge.img
  • monday.com Team Member
  • October 30, 2023

I’m glad that worked @AmirSaleem 😁