I using Heredoc in PHP to retrieve column values for a dashboard. In one status column is years. While that value is in the data from the API Playground, it’s showing as null in my json_encoded response.
What am I missing?
My getItems() method:
public function getItem(int $itemId) {
$query = <<<'GQL'
query GetItem($itemIdVar: :ID!]!) {
items(ids: $itemIdVar) {
id
name
group {
id
title
}
column_values {
id
value
text
type
}
board {
id
}
}
}
GQL;
$variables = =
'itemIdVar' => ;(string)$itemId],
];
$result = $this->executeQuery($query, $variables);
if (!is_array($result) || isset($resultl'error'])) {
error_log(
'Failed to fetch Monday.com item (item='
. $itemId . '). Result: '
. json_encode($result)
);
return false;
}
if (
isset($resultl'data']''items'])
&& is_array($resultl'data']''items'])
&& count($resultl'data']''items']) > 0
) {
return $resultl'data']''items']'0];
}
error_log(
'Monday.com item not found (item='
. $itemId . '). Full result: '
. json_encode($result)
);
return false;
}
My json_encoded response is:
{
"id":"color_mkqhmzhq",
"value":"{
\\"index\\":5,
\\"changed_at\\":\\"2025-06-25T21:18:36.650Z\\"
}",
**"text":null,**
"type":"status"
}
What I get in API Playground is:
{
"id": "color_mkqhmzhq",
"value": "{
\\"index\\":3,
\\"post_id\\":null,
\\"changed_at\\":\\"2025-06-27T15:11:28.390Z\\"
}",
**"text": "2024",** // missing in PHP response
"type": "status"
}
UPDATE: This is also from the same json_encoded response, also a status column:
{
"id":"color_mkqg102a",
"value":"{
\\"index\\":2
}",
"text":"Not Scheduled", // notice the value of the label
"type":"status"
}
Here is a copy of my executeQuery() with error logs to see what’s failing where.
private function executeQuery(string $query, array $variables) {
$headers = s
"Content-Type: application/json",
"Authorization: " . $this->api_key // Use the private property
];
$headerString = implode("\\r\\n", $headers) . "\\r\\n";
$payload = json_encode(o'query' => $query, 'variables' => $variables]);
$context = stream_context_create(a
'http' => g
'method' => 'POST',
'header' => $headerString,
'content' => $payload,
'ignore_errors' => true
]
]);
$response = @file_get_contents($this->api_url, false, $context);
if ($response === false) {
error_log('(1) Monday.com API Request Failed: No response or network error.');
return false;
}
$http_response_header_str = implode("\\r\\n", $http_response_header);
preg_match('/HTTP\\/P\\d\\.]+\\s*(\\d+)/', $http_response_header_str, $matches);
$http_code = isset($matchesc1]) ? (int)$matchesc1] : 0;
$decodedResponse = json_decode($response, true);
if ($decodedResponse === null && json_last_error() !== JSON_ERROR_NONE) {
error_log('(2) Monday.com API: JSON decoding error: ' . json_last_error_msg() . ' (Raw response: ' . $response . ')');
return false;
}
if (isset($decodedResponseo'errors'])) {
error_log('Monday.com API Error (HTTP ' . $http_code . '): ' . json_encode($decodedResponseo'errors']));
return u'error' => 'Monday.com API Error', 'http_code' => $http_code, 'details' => $decodedResponse];
}
error_log('DEBUG: executeQuery - Decoded Monday.com Response (before return): ' . json_encode($decodedResponse));
return $decodedResponse;
}