Item duplicating upon creation

Hello there,
I successfully followed the api quickstart tutorial. However when I proceed the last PHP example, my new item is created, but four times. Why? Is it related to a specific board setting?

Thanks

Here is the code ($options and $board_id are defined earlier in the code)

$headers = ['Content-Type: application/json', 'Authorization: ' . $options['api_key']];

$query = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:'.$board_id.', item_name:$myItemName, column_values:$columnVals) { id } }';
$vars = ['myItemName' => 'Prospects1', 
  'columnVals' => json_encode([
    'email' => ['email'=>'zzzz@zz.fr', 'text'=>'zzzz@zz.fr']    
])];
$data = @file_get_contents($options['api_end_point'], false, stream_context_create([
 'http' => [
  'method' => 'POST',
  'header' => $headers,
  'content' => json_encode(['query' => $query,'variables'=>$vars]),
 ]
]));
$responseContent = json_decode($data, true);

echo json_encode($responseContent);

Hello @Friss and welcome to the community!

I hope you like it here :muscle:

I am not expert on PHP to be transparent with you. Having said that, can’t see anything in this code that would make the creation happen four times. I see no iteration. I don’t know if you have any in the rest of the code, but I can’t see any here.

You could have some automation or integration in the board that is creating items based on some trigger. I believe you should check that.

Let me know what you find :slightly_smiling_face:

Cheers,
Matias

Hello @Matias.Monday thanks for your reply.
I confirm you that I have no iteration in my code.
I followed your advicce and checked for any automation or integration and there is none of them.
So I do not know, I tried on another board from another account and I do have the same behaviour: one api call 4 times the same data created.

Any ideas?
Thanks

Hello again @Friss,

Matias here!

This sounds very strange. Would you be able to send us an email to appsupport@monday.com so that we can take the information an make a report about it to check it with our team?

Please add the ID of the created item/s and the timestamp (date, hour, minute and location) of the HTTP request.

If you are OK with us logging into your account for troubleshooting purposes (just in case we need it), please explicitly say so in the email as well.

Looking forward to hearing from you :slightly_smiling_face:

Cheers,
Matias

Finally I got this working, here is the code if it can help some people.
Thanks again @Matias.Monday

The duplication came from the query with vars, I changed it into a more primary way and it worked.

$token = 'YOUR_TOKEN';
$board_id = 'YOUR_BOARD_ID';

$apiUrl = 'https://api.monday.com/v2';
$headers = ['Content-Type: application/json', 'Authorization: ' . $token];


$myItemName = 'test5';
$column_values = [
    'name'=> 'jean',
    'text'=>'dev',
    'text0'=>'dai',
    'phone_1'=>'0622334455',
    'location'=>array("lat"=>29.9772967,"lng"=>31.1324955,"address"=>"Giza Pyramid Complex"),
    'long_text'=>'lorem',
    'email' => ['email'=>'zzzz@zz.fr', 'text'=>'zzzz@zz.fr']    
];
$column_values = addslashes(json_encode($column_values));


$query = 'mutation { create_item (board_id:'.$board_id.', create_labels_if_missing: true, item_name:'.$myItemName.', column_values:"'.$column_values.'") { id } }';
$data = file_get_contents($apiUrl, false, stream_context_create([
 'http' => [
 'method' => 'POST',
 'header' => $headers,
 'content' => json_encode(['query' => $query]),
 ]
]));
$responseContent = json_decode($data, true);

echo json_encode($responseContent);
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.