Hello,
I have been working with the Monday API for a while now. So far without any problems. But now I have a problem and do not get further.
My Setup:
- 2 web pages on one website
- each a JS file calls the same php file
- 1 PHP file that performs a mutation
The structure of the files
JS file from page A (snippet)
$.ajax({
url: "/mondayapi.php", //the page containing php script
type: "post", //request type,
data: { 'myBoardId': parseInt(board_id_bewerbungen), 'myItemId': mondayItemId, 'queryVariables': queryVariables, 'category': 'updateMonday' },
success: function (result) {
let reslt_ojb = JSON.parse(result)
console.log(reslt_ojb)
if (reslt_ojb.hasOwnProperty('error_code')) {
console.log('error')
showToast('Daten konnten nicht aktualisiert werden', 'bg-danger')
} else {
showToast('Erfolgreich aktualisiert', 'bg-success')
}
}
}).fail(function () {
alert("error");
})
JS file from page B (snippet)
$.ajax({
url: "/mondayapi.php", //the page containing php script
type: "post", //request type,
data: { 'myBoardId': parseInt(board_id_bewerbungen), 'myItemId': mondayItemId, 'queryVariables': queryVariables, 'category': 'updateMonday' },
success: function (result) {
console.log(result)
let reslt_ojb = JSON.parse(result)
console.log(reslt_ojb)
if (reslt_ojb.hasOwnProperty('error_code')) {
showToast('Daten konnten nicht aktualisiert werden', 'bg-danger')
} else {
showToast('Erfolgreich aktualisiert', 'bg-success')
}
}
}).fail(function () {
alert("error");
})
php file (snippet)
function updateMonday($myBoardId, $myItemId, $queryVariables)
{
$query = 'mutation ($myBoardId:Int!, $myItemId:Int!, $queryVariables:JSON!) { change_multiple_column_values(item_id:$myItemId, board_id:$myBoardId, column_values: $queryVariables) { id }}';
$vars = [
'myBoardId' => (int)$myBoardId,
'myItemId' => (int)$myItemId,
'queryVariables' => $queryVariables
];
$token = '1234567890';
$apiUrl = 'https://api.monday.com/v2';
$headers = ['Content-Type: application/json', 'Authorization: ' . $token];
$data = @file_get_contents($apiUrl, 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);
}
From page A everything works without problems. Variable $queryVariables looks linke this. The column is a type of “long-text”.
{"langer_text" : "Some Text"}
On page B the mutation does not work. I get neither an error message nor a success message from the PHP file.
Variable $queryVariables looks linke this. The column is a type of “long-text”.
{"long_text1" : "This text not work"}
A have already checked all other variables in that query. In both scenarios they are correct.
From A I recieve a success message like
data: change_multiple_column_values
id: "3696347409"
From B I recieve just null
null
In scenario B I do not get any erros in my php-log.