[ 'label' => 'Créer un panneau', 'method' => 'POST', 'path' => '/public-api/signs', ], 'update_sign' => [ 'label' => 'Modifier un panneau', 'method' => 'PUT', 'path' => '/public-api/signs/{externalId}', ], 'favorites_count' => [ 'label' => 'Compteur favoris / préférés', 'method' => 'GET', 'path' => '/public-api/entities/favorities/count', ], 'embed_widget' => [ 'label' => 'Générer un widget iframe', 'method' => 'GET', 'path' => '/embeded/{cityId}', 'local' => true, // ne fait pas d'appel API, génère juste le code iframe ], ]; // ------------------------------------------------------------------ // Appel HTTP générique vers l'API PanneauPocket // ------------------------------------------------------------------ function ppApiCall(string $method, string $path, ?array $body = null): array { $ch = curl_init(PP_BASE_URL . $path); $headers = [ 'Authorization: Bearer ' . PP_TOKEN, 'Accept: application/json', ]; $options = [ CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => $method, CURLOPT_TIMEOUT => 15, ]; if ($body !== null) { $headers[] = 'Content-Type: application/json'; $options[CURLOPT_POSTFIELDS] = json_encode($body, JSON_UNESCAPED_UNICODE); } $options[CURLOPT_HTTPHEADER] = $headers; curl_setopt_array($ch, $options); $raw = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlError = curl_error($ch); curl_close($ch); if ($curlError) { return ['ok' => false, 'code' => 0, 'body' => ['error' => $curlError]]; } $decoded = json_decode($raw, true); return [ 'ok' => $httpCode >= 200 && $httpCode < 300, 'code' => $httpCode, 'body' => $decoded ?? $raw, ]; } // ------------------------------------------------------------------ // Petits helpers fonctionnels (map/filter) pour construire les payloads proprement // ------------------------------------------------------------------ function stripEmpty(array $arr): array { return array_filter($arr, static fn($v) => $v !== null && $v !== ''); } // Construit le tableau "documents" à partir des lignes d'URL soumises (une par ligne) function parseDocuments(string $raw): array { $lines = array_map('trim', explode("\n", $raw)); return array_values(array_filter($lines, static fn($l) => $l !== '')); } // ------------------------------------------------------------------ // Traitement du POST // ------------------------------------------------------------------ $result = null; $selected = $_POST['action'] ?? array_key_first($actions); $iframeCode = null; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($actions[$selected])) { $def = $actions[$selected]; switch ($selected) { case 'create_sign': $payload = stripEmpty([ 'id' => $_POST['id'] ?? '', 'title' => $_POST['title'] ?? '', 'content' => $_POST['content'] ?? '', 'startAt' => $_POST['startAt'] ?? '', 'endAt' => $_POST['endAt'] ?? '', 'type' => $_POST['type'] ?? '', ]); $docs = parseDocuments($_POST['documents'] ?? ''); if ($docs) { $payload['documents'] = $docs; } $result = ppApiCall('POST', '/public-api/signs', $payload); break; case 'update_sign': $externalId = $_POST['externalId'] ?? ''; $payload = stripEmpty([ 'title' => $_POST['title'] ?? '', 'content' => $_POST['content'] ?? '', 'startAt' => $_POST['startAt'] ?? '', 'endAt' => $_POST['endAt'] ?? '', 'type' => $_POST['type'] ?? '', ]); $docs = parseDocuments($_POST['documents'] ?? ''); if ($docs) { $payload['documents'] = $docs; } $path = '/public-api/signs/' . rawurlencode($externalId); $result = ppApiCall('PUT', $path, $payload); break; case 'favorites_count': $result = ppApiCall('GET', '/public-api/entities/favorities/count'); break; case 'embed_widget': $cityId = $_POST['cityId'] ?? ''; $mode = $_POST['mode'] ?? 'widget'; $autoNavigation = $_POST['autoNavigation'] ?? '0'; $bgColor = trim($_POST['bgColor'] ?? ''); $query = http_build_query(stripEmpty([ 'mode' => $mode, 'autoNavigation' => $autoNavigation, 'bgColor' => $bgColor, ])); $src = PP_BASE_URL . '/embeded/' . rawurlencode($cityId) . '?' . $query; $style = $mode === 'widgetTv' ? 'position: relative; height: 100%; width: 100%; z-index: 10; border: none' : 'height:518px; width:330px; border:none'; $iframeCode = sprintf( '', htmlspecialchars($src, ENT_QUOTES), $style ); break; } } ?> PanneauPocket — Pilotage

PanneauPocket — Pilotage

Créer un panneau
Modifier un panneau
Compteur favoris / préférés

Aucun paramètre requis — cliquez sur "Exécuter" pour interroger l'API.

Générer un widget iframe

Réponse API — HTTP

Code iframe à intégrer