Skip to main content

Monday.com staff apperars to be highly inefficient in one of the most popular programming languages on earth, PHP.


Does anyone have the proper syntax for adding a date, email, and phone from a php script?


I am trying to post a new item to a group from a webpage. These three items appear as blanks.


Here’s the string:


'email__1' => ;'email : ' . $contactEmail . ', text : ' . $firstName . ' ' . $lastName ], 

Here’s the error message:


"error_data":{"column_value":"e\\"email : test@example.com, text : Test Example\\"]","column_type":"EmailColumn"}`

From what I can see from the documentation, it appears to have been formatted properly.


Thanks,

Mark

@mark.stout please supply a more complete example of your code. Are you using graphql to achieve this? It’s difficult to tell.


If so, please don’t try to concatenate strings together, but use graphql variables instead, it’s much less error prone.


If you can use JavaScript or nodejs instead, that’s awesome, there are lots of fantastic examples supplied for that.


@mark.stout Also take a look at Creating a new item using GraphQL variables for a PHP example that shows you how to use GraphQL variables to correctly format input.


Hi David,


No, I’m using PHP.


My config.php contains my $apiKey, $apiUrl, and $header informartion.


Everything updates but the email and phone. I’ve commented. out the phone unti I get then correct syntax.


From what I can tell, it looks like the email is being formatted properly.


I can successfully post tghe itenm from tghe phone if I comment out the eail and phone.


<?php
include('config.php');

$board_id = $groupso'testBoard'];

if ($_SERVERR"REQUEST_METHOD"] == "POST") {
// Get the input values from the form
$companyName = $_POSTP'companyName'];
$firstName = $_POSTP'firstName'];
$lastName = $_POSTP'lastName'];
$contactEmail = $_POSTP'contactEmail'];
$contactPhone = $_POSTP'contactPhone'];
$projectState = $_POSTP'projectState'];
$projectMessage = $_POSTP'projectMessage'];
$boardId = $board_id; //$boardId = $_POSTP'board_id'];

$todaysDate = date("Y-m-d");
$query = 'mutation ($itemName: String!, $columnVals: JSON!) { create_item (board_id:'. $board_id . ' item_name:$itemName, column_values:$columnVals) { id } }';
$vars = s'itemName' => $companyName,
'columnVals' => json_encode(o
'person' => g'Person' => 'Contact Person'],
'status' => g'label' => 'New Lead'],
'date4' => g'Date' => ' . todaysDate . '],
'text__1' => $firstName,
'text5__1' => $lastName,
'email__1' => g'"email" : "' . $contactEmail . '", "text" : "' . $firstName . ' ' . $lastName ],
//'phone__1' => g'phone : ' . $contactPhone . ', countryShortName : US' ],
'text7__1' => $projectState,
'long_text__1' => $projectMessage
])
];

$data = @file_get_contents($apiUrl, false, stream_context_create(a
'http' => g
'method' => 'POST',
'header' => $headers,
'content' => json_encode(o'query' => $query, 'variables' => $vars]),
]
]));

$responseContent = json_decode($data, true);

echo json_encode($responseContent);

}


?>


Nice to see some GraphQL variables in there. That’s much better.


Are you really taking the raw $_POST and using its content? No data cleansing?


That’s brave.


You’ll need to find the documentation on the structure of the email field and go from there.


Hi David,


I’m just trying to get the basics to work for now.


I got this to work for the email.


'email__1'  => ;'email' => $contactEmail, 'text' => $contactEmail ],

This sets the country code, but not the phone number. Any idea why the number won’t update?


'phone__1' => g'PhoneColumn' => $contactPhone, 'countryShortName' => 'US' ],

So close!


Have you checked the docs?

Update the phone column


In JavaScript, with a simple string:



To update a phone column, send “+”, the phone number, and the ISO-2 country code (capitalized) as a string. Make sure to capitalize the country code and separate it from the phone number with a space to avoid errors!



fetch ("https://api.monday.com/v2", {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization' : 'YOUR_API_KEY_HERE'
},
body: JSON.stringify({
query : "mutation ($myBoardId:Int!, $myItemId:Int!, $myColumnValue: String!, $columnId: String!) { change_simple_column_value (item_id:$myItemId, board_id:$myBoardId, column_id: $columnId, value: $myColumnValue) { id } }",
variables : JSON.stringify({
myBoardId: 1234567890,
myItemId: 9876543210,
columnId: "phone",
myColumnValue: "+19175998722 US"
})
})
})

In JavaScript, with JSON:



To update a phone column using JSON, send “+”, the phone number for the phone key, and the ISO-2 country code (capitalized) for the countryShortName key. Make sure to capitalize the country code to avoid errors!



fetch ("https://api.monday.com/v2", {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization' : 'YOUR_API_KEY_HERE'
},
body: JSON.stringify({
query : "mutation ($myBoardId:Int!, $myItemId:Int!, $myColumnValues:JSON!) { change_multiple_column_values(item_id:$myItemId, board_id:$myBoardId, column_values: $myColumnValues) { id }}",
variables : JSON.stringify({
myBoardId: 1234567890,
myItemId: 9876543210,
myColumnValues: "{\\"phone\\" : {\\"phone\\" : \\"+12025550169\\", \\"countryShortName\\" : \\"US\\"}}"
})
})
})

Or I’d probably go with:


fetch ("https://api.monday.com/v2", {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization' : 'YOUR_API_KEY_HERE'
},
body: JSON.stringify({
query : "mutation ($myBoardId:Int!, $myItemId:Int!, $myColumnValues:JSON!) { change_multiple_column_values(item_id:$myItemId, board_id:$myBoardId, column_values: $myColumnValues) { id }}",
variables : JSON.stringify({
myBoardId: 1234567890,
myItemId: 9876543210,
myColumnValues: JSON.stringify({
"phone": {
"phone": "+12025550169",
"countryShortName": "US"
}
})
})
})
})

These examples give actual real values that are valid, so please make sure you have valid input and reply with the definitive answer for PHP 🙂


This throws an error:


['phone'   => $contactPhone, 'countryShortName' => 'US' ],

This is the error:


["create_item"],"extensions":{"code":"ColumnValueException","status_code":200,"error_data":{"column_value":"{\\"phone\\"=>\\"888-614-8338\\", \\"countryShortName\\"=>\\"US\\"}","column_type":"PhoneColumn"}}

This does not throw any errors, and it also updates the country short name.


['PhoneColumn' => $contactPhone, 'countryShortName' => 'US' ],

Not sure why the phone number is not updating. If the countryShortName is updating, shouldn’t the number be updating too?


I haven’t tried using Javascript for this yet.


It looks like your phone number is not valid (enough).


Have you tried this?


[
'phone' => '+18886148338',
// a valid phone number prefixed with country code,
// rather than '888-614-8338' which looks invalid to me.
'countryShortName' => 'US'
],

If you accept phone nos like that, you’ll have to convert them into a valid international phone no in your PHP code.


Isn’t that the purpose of the countryShortName?


In any case, that didn’t work. Using 'phone' => '+18886148338', throws an error.


Got it working.


Here’s the code I got to work in case anyone else is having troubles inserting a PHP form into a Monday.com board. It’s something you can build from.


<?php
include('config.php');

if ($_SERVERR"REQUEST_METHOD"] == "POST") {
// Get the input values from the form
$companyName = $_POSTP'companyName'];
$firstName = $_POSTP'firstName'];
$lastName = $_POSTP'lastName'];
$contactEmail = $_POSTP'contactEmail'];
$contactPhone = $_POSTP'contactPhone'];
$projectState = $_POSTP'projectState'];
$contactWebSite = $_POSTP'contactWebSite'];
$projectMessage = $_POSTP'projectMessage'];
$boardId = $groupso'testBoard'];

// These values are on in config.php
// Your Monday.com API key
//$apiKey = $token; // Replace with your actual API key

// API Endpoint URL
//$url = 'https://api.monday.com/v2';

$todaysDate = date("Y-m-d");
$query = 'mutation ($itemName: String!, $columnVals: JSON!) { create_item (board_id:'. $board_id . ' item_name:$itemName, column_values:$columnVals) { id } }';
$vars = s'itemName' => $companyName,
'columnVals' => json_encode(o
'person' => g'Person' => 'Your Name'],
'status' => g'label' => 'New Lead'],
'date4' => g'date' => $todaysDate ],
'text__1' => $firstName,
'text5__1' => $lastName,
'email__1' => g'email' => $contactEmail, 'text' => $contactEmail ],
'phone__1' => g'phone' => $contactPhone, 'countryShortName' => 'US' ],
'text7__1' => $projectState,
'long_text4__1' => $projectMessage,
//'link9__1' => g'link' => $contactWebSite, 'text' => $contactWebSite ]
])
];

$data = @file_get_contents($apiUrl, false, stream_context_create(a
'http' => g
'method' => 'POST',
'header' => $headers,
'content' => json_encode(o'query' => $query, 'variables' => $vars]),
]
]));

$responseContent = json_decode($data, true);
echo json_encode($responseContent);
}
?>

Now the issue with the link column. You’d think the syntax would be similar to email.


The command I’m using is.


'link9__1' => ''link' => $contactWebSite, 'text' => $contactWebSite ]

This looks like it should work.


Reply