Create Multiple items at once

Hello All,

We are using Monday for 2 months now and we like it very much.
Now i am programming with the API and i want to create multiple items at once.

How does the mutation look if i want to create multiple items at once.
This is my mutation now

mutation {
 create_item (
  board_id:8465,
  group_id:"topics",
  item_name:"ItemName",
  column_values:"{\"status\":{\"label\":\"ToDo\"}}"
 ) {
  id
 }
}

Thanks.

HI @Tieme! Thanks for posting about this one - currently our API does not support the ability to create multiple items at once. I’d be happy to pass this request onto our team for consideration :slight_smile: Cheers!

Hi @lauralev,
Thank you for the reply.
Please pass this request on to the team, I think it is a very nice addition to the API.
I am curious what their reaction would be…
Cheers!

1 Like

Not sure of your needed scenario; but you could you could build a windows client and use c# and GraphQL library to loop and dynamically create each item you need; similar to how I am creating this notification. Maybe this will help you??? :slight_smile:

Here is an example of creating a notification based on values passed to a procedure; build my query and pass it to a GraphQLClient, etc.

static async Task RunMutableNotification(string user_id, string item_id, string item_name)
{
string strText = ““API Completed Task Scan Notification; Pulse: (” + item_id + “) " + item_name +
" Status Updated to Completed and Moved to Completed Group!””;

        //Hardcoded the value we will be setting it to "Completed"
        string query = "mutation {create_notification (user_id: " + user_id + ", " +
                   "target_id: " + item_id + ", " + "text: " + strText + ", " + "target_type: " + "Project) { text } }";

        var request = new GraphQLRequest()
        {
            Query = query
        };

        var graphQLClient = new GraphQLClient("https://api.monday.com/v2/");
        graphQLClient.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR BEARER CODE WOULD GO HERE");
        graphQLResponse = await graphQLClient.PostAsync(request);

        graphQLClient.Dispose();

    }

@kfogarty Thanks fot the script,
I am programming in PHP and have created a class now for creating a Mutation Query.

class MondayMutationCreateItemsQuery
{
    private $Mutations;
    private $BoardID;
    private $GroupID;
    private $ItemName;
    private $ColumnValues;

    public function __construct()
    {
        $this->Mutations = '';
    }

    public function setBoardID(int $BoardID)
    {
        $this->BoardID = $BoardID;
    }

    public function setGroupID(string $GroupID)
    {
        $this->GroupID = $GroupID;
    }

    public function setItemName(string $ItemName)
    {
        $this->ItemName = $ItemName;
    }

    public function setColumnValues(array $ColumnValues)
    {
        $this->ColumnValues = json_encode(json_encode($ColumnValues));
    }

    public function GetQuery()
    {
        $Check = $this->CheckValues();
        if(!is_bool($Check))
        {
            return $Check;
        }

        $Mutation = 'mutation {';
            $Mutation .= 'create_item (';
            $Mutation .= ' board_id:'.$this->BoardID.',';
            $Mutation .= ' group_id:"'.$this->GroupID.'",';
            $Mutation .= ' item_name:"'.$this->ItemName.'" ';
            $Mutation .= ' column_values:'.$this->ColumnValues;
            $Mutation .= ') { id }';
        $Mutation .= '}';

        return  '{"query" : '. json_encode($Mutation) . ' }';
    }

    private function CheckValues(){

        if($this->BoardID == ''){
            return 'Error: Empty BoardID.';
        }
        if($this->GroupID == ''){
            return 'Error: Empty GroupID.';
        }
        if($this->ItemName == ''){
            return 'Error: Empty ItemName.';
        }
        if($this->ColumnValues == ''){
            return 'Error: Empty ColumnValues.';
        }
        return TRUE;
    }
} 

I works like this.

private function CreateMondayItem(array $EndedProductContracts)
{
    $Monday = $this->App->MondayMutationCreateItems();
    $Monday->setBoardID($this->MondayBoard);
    $Monday->setGroupID('topics');
    foreach ($EndedProductContracts as $EndedProductContract)
    {
        $this->App->Log()->debug('Create Monday item ' . $EndedProductContract['Domain']);
        $Monday->setItemName($EndedProductContract['Domain']);
        $Monday->setColumnValues([
            'status8' => ['label' => $this->LabelName ],
            'status'  => ['label' => 'Nog verwerken' ],
            'date4'   => ['date'  => $EndedProductContract['Date'] ],
            'link'    => [ 'url'  => $EndedProductContract['Link']['url'], 'text' => $EndedProductContract['Link']['text']]
        ]);
        $Reponse = $this->App->MondayRequest( $Monday->GetQuery() );
        $this->App->Log()->debug('Monday Item Created ', ['response' => $Reponse]);
    }
}

Tieme,

Great; I am glad you are on your way. I just wanted to make sure that you were aware that using a looping mechanism would allow you to create as many mutations as you want…

Take care
:blush:

Regards,

Kevin

cde_registeredtrademark_0f838930-a72c-46ec-a9d0-e4cf666f1a04.png

cde-facebook-logo_2250370c-7a60-48dd-9fee-739a1d0c993d.png

cde-twitter-logo_47bd0ad0-4413-4041-a63d-6b61439b48da.png

cde-linkedin-logo_ea926bab-4b15-4f14-b9e1-a2b360a15040.png

cde-youtube-logo_5ba8c41b-f5ed-4d8e-886c-ed3a50eefe11.png

Does anyone know if the feature request associated here was resolved?

Yes, looping mechanisms work fine, but have two downfalls:

  1. Take more total time due to additional handshakes and transfers
  2. Result in additional API calls, impacting the amount of calls remaining in a license period.
1 Like

Hey @morhriveion - not just yet. It’s something we’re hoping to tackle in the future however.

-Daniel

Is there any update on this one? :pray:

@etaytch

Thank you for reaching out about this! Currently, not just yet, and I’m afraid I can’t confirm when this would be added to the platform. As of now, it seems like creating multiple items in the same mutation is not going to be an option in the next couple of months, though.

I hope that helps, and thanks for keeping an eye out for this feature request!

-Alex

Any update on this one guys? Is there an ETA or product roadmap we could see?

1 Like

Monday currently supports 10rows per board, but importing thousands of rows through the API one at a time is completely impractical. Importing data from an Excel file is fairly fast, but there doesn’t seem to be a programmatic way to do that.

Questions:

  • is there a way to import an excel file programmatically via the API?
  • is it not possible to include multiple create_item mutations in the same query (i.e. same http request)?
1 Like

I hope this feature gets added in the API.
We are running the API via Google Apps Scripts and currently using a loop to create the mutations but this is inefficient especially on large data because Google has certain quotas like execution limit and API fetches that we also need to consider.
Really hoping we’ll get an update on this.

Having this functionality would be really helpful for many reasons, but for the moment I guess we need to loop through the array of items we need to create.
This is what I’m doing for creating subitems, and for me the order is very important, so I can’t send the requests in parallel. I have to block my code until the request comes back to send the new one, because I need a particular order.
Is there a way to define this other than creating a number column for item ordering?

Hello @NADEBUM and @carlosdelgado !

You can send multiple mutations in one request:

mutation{
  createItem1: create_item(board_id: 1234567, item_name:"This is a new Item 1") {
    id
    name
  }
  createItem2: create_item(board_id: 1234567, item_name:"This is a new Item 2") {
    id
    name
  }
}

You would, obviously, get one response per call with the information from all the mutations sent.

Carlos, I did not fully understand the order you are describing. Can you please elaborate (and maybe give me an example)?

1 Like

I love using this one, because i need to create items in several boards for the same event in an outside application. A single call just cuts down on the API activity in general. Establishing the connections is half the latency, and putting multiple operations in a single mutation eliminates much of that.

I also combine column updates to many columns, items, and item moves in the same mutation. They have a high complexity sometimes but not really any more than many separate queries - but now the Monday.com engine processes everything in a nearly simultaneous fashion (though it definitely appears at this time all the columns update in the order listed in the mutation and the operations happen in the order listed)

1 Like

Can we find any documentation for this?
Is createItem1, createItem2 a keyword or a variable?
I’d like to try this method.
Thank you!

Hello @NADEBUM !

You can check the documentation here.

createItem1 and createItem2 would be the names for each creation so that you can tell them apart in the response.

Cheers,
Matias

Am I correct in the assumption that this will not work for the add_file mutation? When I try it, I get an “Unsupported query” error. I don’t know if it’s because I’m doing it wrong or if it’s really just not supported.

Hello @lyle!

That is correct. It will not work for that specific mutation.

Cheers,
Matias

1 Like