Skip to main content

Hi,


(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]:


LOCALHOST:

Array ( myItemName] => ignoreme1235 gcolumnVals] => {"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}


SERVER:

Array ( omyItemName] => mondayfunday1234 ycolumnVals] => {"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:

`

$MONDAY_BOARD_ID = env(‘MONDAY.COM.BOARD_ID’);

$MONDAY_GROUP_ID = env(‘MONDAY.COM.GROUP_ID’);

$MONDAY_TOKEN = env(‘MONDAY.COM.TOKEN’);

$MONDAY_API_URL = env(‘MONDAY.COM.API_URL’);


	  	$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 .',
item_name:$myItemName,
column_values:$columnVals) { id } }';

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

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

'columnVals' => json_encode(l
"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" => r"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(a
'http' => t
'method' => 'POST',
'header' => $headers,
'content' => json_encode(''query' => $query, 'variables' => $vars]),
]
]));
$responseContent = json_decode($data, true);

`

Hi again @jth.psp 👋 Good to see you as part of the community 🙂


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?


-Alex


@jth.psp


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(e'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!



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


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


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!


@jth.psp


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 🙂 you rock!


-Alex


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 !


@jth.psp


Glad to hear you got it working 🙂


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