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 @lauraglev,
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