# Getting data from cockpit collection not working

**URL:** <https://discourse.getcockpit.com/t/getting-data-from-cockpit-collection-not-working/3205>\
**Category:** Support\
**Created:** [June 6, 2025, 12:46pm UTC](https://discourse.getcockpit.com/t/getting-data-from-cockpit-collection-not-working/3205 "2025-06-06T12:46:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tiger123456781111](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/tiger123456781111/32/1548_2.png) [@Tiger123456781111](https://discourse.getcockpit.com/u/Tiger123456781111)\
**Post date:** [June 6, 2025, 12:46pm UTC](https://discourse.getcockpit.com/t/getting-data-from-cockpit-collection-not-working/3205/1 "2025-06-06T12:46:41Z")

</div>

Hello,  
I’m trying to get data from collection “vijesti” i created in cockpit backend but cant get it work and i got JSON decode error: Syntax error, Raw response: . I put cockpit files in “cockpit” folder and folder is with other html php js etc… Can you guys help bcs i cant find solution to simple fetch data. Version oh php server is 8.3. Its siple html site with index.php. I would really appreciate your help. Thanks in advance. Php file for fetching:

\\<?php  
// Show all errors  
ini\_set(‘display\_errors’, 1);  
ini\_set(‘display\_startup\_errors’, 1);  
error\_reporting(E\_ALL);

// API setup  
$api\_url = ‘MYLINK/cockpit/api/collections/get/vijesti’;  
$api\_token = ‘API-ON-PROFILE’;

// Initialize cURL  
$ch = curl\_init($api\_url);  
curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, true);  
curl\_setopt($ch, CURLOPT\_HTTPHEADER, [  
“Cockpit-Token: $api\_token”  
]);

$response = curl\_exec($ch);  
$http\_code = curl\_getinfo($ch, CURLINFO\_HTTP\_CODE);  
$error = curl\_error($ch);  
curl\_close($ch);

if ($response === false || $http\_code !== 200) {  
echo “

**Greška u povezivanju s CMS-om.**

”;  
echo “
```
HTTP status: $http_code\ncURL greška: $error\nRaw response:\n” . htmlspecialchars($response) . “
```
”;  
exit;  
}

// Decode JSON  
$data = json\_decode($response, true);

if (json\_last\_error() !== JSON\_ERROR\_NONE) {  
echo "

**Greška u dekodiranju JSON odgovora:**" . json\_last\_error\_msg() . “

”;  
echo “
```
JSON odgovor (raw):\n” . $response . “
```
”;  
exit;  
}

// Display entries  
if (isset($data[‘entries’]) && count($data[‘entries’])) {  
foreach ($data[‘entries’] as $entry) {  
echo ‘

’;  
echo ’ 
‘;  
echo ’ 
### ’ . htmlspecialchars($entry[‘Naslov’]) . ‘
’;  
echo ’ 

’ . nl2br(htmlspecialchars($entry[‘Opis’])) . ‘

’;  
echo ’ 
';  
echo ‘
’;  
}  
} else {  
echo ‘

**Nema vijesti za prikaz ili prazna kolekcija.**

’;  
echo “
```
Raw response:\n” . htmlspecialchars($response) . “
```
”;  
}  
?\>
