Mutation returns null (no success and no error message)

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.

Hello there @mm_hw,

It looks like your issue may lie in your code and the mutation is probably never reaching monday for B.

I am not experienced with PHP but I would check how the JS files are calling the PHP file. It could be related to a matter of where the file is stored (in which folder) and how it is being called or something like that.

Is there an PHP expert in here who can contribute in solving this issue?

Hello @Matias.Monday ,

Thanks for your reply.

I have a central php file that handles all the request with Monday API. In total I have 10 pages. 9 of them work without problems (as described in scenario A). Only the one page does not work (scenario B).
But the file is also called correctly in scenario B (see screenshot). Only the variable $data in B has the value null.

Each of these 10 pages has its own JS file, all in the same folder and all accessing a single PHP file.

The code is always the same, except that the value of the variable changes.

If I enter the query by hand in Monday Playground, it works. But as soon as I run it from the php code, it does not work.

Hello again,

From what you told me, then I can assume that the issue does not lie on the mutation itself because it would fail in the Playground as well.

In this case, we will need to see if someone who is experienced with PHP can see something in the script you sent that might be causing this.

Hello,
I have found the problem. The board was defined as a template. I created a board from the template and I worked with this board. Now it works.

Note: From a template you can read data with the API but you can not write data to such a board.

Hello again,

I am glad you found the source of the issue!

Let us know if you need anything else!

Cheers,
Matias