APIv2 create_item mutation working in local, but returning null when in server [PHP]


(Pardon if this has been raised before but as far as i can search, can’t find a similar posting so here goes…)

I’m having a problem with create_item mutation.
It works on localhost (tried PHP7.2 and PHP7.4) and returns a proper id
but when we are running it in our test env server (cpanel with apache + PHP7.2.32), only “null” is returned.

I’m starting to doubt that it is code related and perhaps related to PHP setup? Maybe we missed a prerequisite somewhere. Any help would be appreciated (Thanks in advance)

I tried logging the returned JSON to compare [redacted some info]:

Array ( [myItemName] => ignoreme1235 [columnVals] => {"numbers4":"1","status_1":{"label":"XXX"},"package":{"label":"XXX"},"task_date_1":{"date":"2020-07-31"},"client_name5":"ignoreme1235","client_name50":"ignoreme1235","phone":{"phone":"","countryShortName":"US"},"mobile_phone":{"phone":"","countryShortName":"US"},"primary03":null,"business_type":"ignoreme1235, ignoreme1235, ignoreme1235, ignoreme1235, DE, 12344","setup_fee":"999.00","eft":"499.00","sold_by":{"label":"XXX"},"long_text":{"text":"ignoreme1235"},"numbers":"31","text8":"20200731224555"} ) {"data":{"create_item":{"id":"99999999"}},"account_id":9999999}

Array ( [myItemName] => mondayfunday1234 [columnVals] => {"numbers4":"1","status_1":{"label":"XXX"},"package":{"label":"XXX"},"task_date_1":{"date":"2020-07-31"},"client_name5":"mondayfunday1234","client_name50":"mondayfunday1234","phone":{"phone":"","countryShortName":"US"},"mobile_phone":{"phone":"","countryShortName":"US"},"primary03":null,"business_type":"mondayfunday1234, mondayfunday1234, mondayfunday1234, mondayfunday1234, CO, 12345","setup_fee":"999.00","eft":"499.00","sold_by":{"label":"XXX"},"long_text":{"text":"mondayfunday1234"},"numbers":"31","text8":"20200731231626"} ) null

relevant Laravel PHP code:

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

			$query = 'mutation ($myItemName: String!, $columnVals: JSON!) { 
				create_item (
					board_id:' . $MONDAY_BOARD_ID .', 
					group_id:' . $MONDAY_GROUP_ID .', 
					column_values:$columnVals) { id } }';

			$item_name = $REDACTED_VAR;
			$salesperson_fullname = $REDACTED_VAR;
			$agreement_no = $REDACTED_VAR;

			$vars = [
					'myItemName' => $item_name, 

			  	'columnVals' => json_encode([
						"numbers4" => $REDACTED_VAR,
			      "status_1" => ['label' => $REDACTED_VAR],
			      "package" => ['label' => $REDACTED_VAR],
			      "task_date_1" => ['date' => date("Y-m-d")],
			      "client_name5" => $REDACTED_VAR,
			      "client_name50" => $REDACTED_VAR,
			      "phone" => ["phone" => $REDACTED_VAR, "countryShortName"=>"US"],
			      "mobile_phone" => ["phone" => $REDACTED_VAR, "countryShortName"=>"US"],
			      "primary03" => $REDACTED_VAR,
			      "business_type" => $REDACTED_VAR,
			      "setup_fee" => $REDACTED_VAR,
			      "eft" => $REDACTED_VAR,
			      "sold_by" => ["label" => $salesperson_fullname],
			      "long_text" => ["text" => $REDACTED_VAR],
			      "numbers" => date('d'),
			      "text8" => $agreement_no,

			\Log::debug("monday query vars: " . print_r($vars));

			$data = @file_get_contents($MONDAY_API_URL, false, stream_context_create([
			 'http' => [
			 'method' => 'POST',
			 'header' => $headers,
			 'content' => json_encode(['query' => $query, 'variables' => $vars]),
			$responseContent = json_decode($data, true);


1 Like

Hi again @jth.psp :wave: Good to see you as part of the community :slight_smile:

To be transparent with you, I do not have much experience working with PHP at all, so I’m afraid I am not able to provide more specific guidance here, but I do hope someone within the community will be able to take a further look and provide better suggestions than me. That said, I found this part in your debug log a bit odd - it seems like the cPanel server isn’t connecting to the API URL correctly, at least from what I am able to gather:

Do you think this could be the culprit here?



Hi there!

I have done some work with Laravel and the monday API.

We use the Guzzle package for our requests. This is an example of the call that we use. I haven’t used the file_get_contents option though.

try {
        $guzzleClient = new Client(array('headers'=>array('Content-Type'=>'application/json', 'Authorization'=>$this->token)));
        $response = $guzzleClient->post($this->mondayAPIUrl, ['body' => json_encode(['query' => $query, 'variables' => $vars])]);
    } catch (\GuzzleHttp\Exception\ClientException $e) {
        $response = $e->getResponse();
        if ($response->getStatusCode() == 401) {
            throw new InvalidAPIKeyException("Invalid Monday.com API V2 Key");
        } else {
            throw new Exception("Monday.com API Exception");

I hope this will assist you


Ok, I will try that. Thanks!

1 Like

it seems like the cPanel server isn’t connecting to the API URL correctly

Yes suspecting this too, however there is no error message so we are not sure where to begin investigating that

1 Like

Tried the guzzle approach. Same problem. Still receiving “null”

@jth.psp Are you running cPanel on your own computer? Or is it hosted elsewhere?

Is there any chance that the is a firewall blocking the call?

Null is a weird response… you usually get an error back relating back to what has happened.

Can you please let me know what status code you are getting back?

$response->getStatusCode() should work before the Catch

1 Like

Hi @mitchell.hudson , the cPanel is on a remote server. I could try to ask the system admin about that.
Will try the status code thing in a bit. Thanks!

1 Like


Thank you for your patience and willingness to get this to work and I’m hoping we can get this sorted for you together!

@mitchell.hudson thank you so much for providing some more helpful suggestions here :slight_smile: you rock!


Late update: (there seemed to be a problem with my other browser, my earlier message didnt get posted here)
There was apparently a problem with my headers when I tried guzzle the first time earlier. (lack of sleep got the best of me lol)
When I fixed that, the API call went without a hitch.

Thanks again to both of you @AlexSavchuk and @mitchell.hudson !

1 Like


Glad to hear you got it working :slight_smile:

Feel free to reach out to the community if you have any more questions !

1 Like