Aller au contenu

API REST - Informations Officielles

Télécharger cette page en Markdown


Endpoints Publics

GET /api/get_infos.php

Récupère les informations officielles publiées dans un rayon géographique.

Paramètres

Nom Type Requis Description
latitude float Oui Latitude utilisateur (-90 à 90)
longitude float Oui Longitude utilisateur (-180 à 180)
rayon int Non Rayon en mètres (défaut: 10000)
code_insee string Non Filtrer par commune
limit int Non Limite résultats (défaut: 50, max: 200)

Exemple Requête

curl "https://urbafix.fr/api/get_infos.php?latitude=43.7764&longitude=7.4977&rayon=5000"

Réponse Succès

{
  "success": true,
  "count": 2,
  "infos": [
    {
      "id": 1,
      "titre": "Travaux rue Victor Hugo",
      "description": "Réfection de la chaussée du 25 au 30 janvier",
      "type_info": "TRAVAUX",
      "latitude": 43.7750,
      "longitude": 7.5030,
      "adresse": "Rue Victor Hugo, 06500 Menton",
      "rayon_metres": 500,
      "date_publication": "2026-01-20 10:00:00",
      "date_expiration": "2026-01-30 18:00:00",
      "distance": 1523.45,
      "mairie": {
        "id": 1,
        "nom": "Mairie de Menton"
      },
      "photos": [
        "https://urbafix.fr/uploads/infos/photo1.jpg"
      ]
    }
  ]
}

Codes d'Erreur

Code Message Description
400 Paramètres latitude et longitude requis Coordonnées manquantes
400 Latitude invalide Hors plage -90/90
400 Longitude invalide Hors plage -180/180

POST /api/register_push_endpoint.php

Enregistre un endpoint UnifiedPush pour recevoir des notifications.

Headers

Content-Type: application/json

Body JSON

{
  "endpoint": "https://ntfy.sh/up1234567890abcdef",
  "device_id": "abc123def456",
  "latitude": 43.7750,
  "longitude": 7.5030,
  "preferences": {
    "travaux": true,
    "evenements": true,
    "alertes": true,
    "annonces": false
  }
}
Champ Type Requis Description
endpoint string Oui URL du distributeur UnifiedPush
device_id string Non Fingerprint device (anonyme)
latitude float Non Position pour ciblage géo
longitude float Non Position pour ciblage géo
preferences object Non Opt-in par type d'info

Réponse Succès

{
  "success": true,
  "message": "Endpoint enregistré"
}

Réponse Mise à Jour

{
  "success": true,
  "message": "Endpoint mis à jour"
}

RGPD

Aucun identifiant device sensible (IMEI, Android ID) n'est transmis. Le device_id est un fingerprint SHA-256 optionnel.


Endpoints Admin

Authentification

Ces endpoints nécessitent une session admin active (rôle admin, gestionnaire ou superadmin).

POST /api/admin/create_info.php

Crée une nouvelle information officielle.

Headers

Content-Type: application/json
Cookie: PHPSESSID=xxx

Body JSON

{
  "mairie_id": 1,
  "titre": "Travaux rue Victor Hugo",
  "description": "Réfection complète de la chaussée",
  "type_info": "TRAVAUX",
  "latitude": 43.7750,
  "longitude": 7.5030,
  "adresse": "Rue Victor Hugo, 06500 Menton",
  "rayon_metres": 500,
  "date_debut_publication": "2026-01-25 08:00:00",
  "date_expiration": "2026-01-30 18:00:00"
}
Champ Type Requis Description
mairie_id int Oui ID de la mairie
titre string Oui Titre (max 255 car.)
description string Oui Description complète
type_info enum Oui TRAVAUX, EVENEMENT, ALERTE, ANNONCE
latitude float Oui Latitude du point central
longitude float Oui Longitude du point central
adresse string Non Adresse textuelle
rayon_metres int Non Rayon zone (défaut: 1000)
date_debut_publication datetime Non Publication différée
date_expiration datetime Non Fin de visibilité

Réponse Succès

{
  "success": true,
  "info_id": 123,
  "message": "Information créée en brouillon (publication programmée le 2026-01-25 08:00:00)"
}

POST /api/admin/publish_info.php

Publie une information (passage de BROUILLON à PUBLIE ou PROGRAMME).

Body JSON

{
  "info_id": 123,
  "send_notification": true
}
Champ Type Requis Description
info_id int Oui ID de l'information
send_notification bool Non Envoyer notification push (défaut: false)

Logique de publication

Logique de décision de l'endpoint publish_info.php

Réponse Succès (Immédiat)

{
  "success": true,
  "message": "Information publiée",
  "statut": "PUBLIE",
  "notification_sent": true
}

Réponse Succès (Programmé)

{
  "success": true,
  "message": "Information programmée pour le 2026-01-25 08:00:00",
  "statut": "PROGRAMME"
}

POST /api/admin/update_info.php

Met à jour une information existante.

Body JSON

{
  "info_id": 123,
  "titre": "Nouveau titre",
  "description": "Nouvelle description",
  "rayon_metres": 1000
}

Restrictions

  • Les infos PUBLIE ne peuvent pas être modifiées (sauf date_expiration)
  • Seules les infos BROUILLON et PROGRAMME sont entièrement éditables

POST /api/admin/disable_info.php

Désactive une information publiée.

Body JSON

{
  "info_id": 123
}

Réponse

{
  "success": true,
  "message": "Information désactivée",
  "statut": "DESACTIVE"
}

DELETE /api/admin/delete_info.php

Supprime définitivement une information.

Body JSON

{
  "info_id": 123
}

Suppression

Cette action est irréversible. Les photos associées sont également supprimées (CASCADE).


Types d'information

Type Emoji Couleur Description
TRAVAUX 🚧 #F59E0B (amber) Chantiers, fermetures
EVENEMENT 🎉 #8B5CF6 (purple) Manifestations, fêtes
ALERTE ⚠ #EF4444 (red) Urgences, risques
ANNONCE 📢 #3B82F6 (blue) Communications

Exemples cURL

Récupérer les infos proches

curl "https://urbafix.fr/api/get_infos.php?latitude=43.7764&longitude=7.4977" | jq

Enregistrer endpoint push

curl -X POST https://urbafix.fr/api/register_push_endpoint.php \
  -H "Content-Type: application/json" \
  -d '{
    "endpoint": "https://ntfy.sh/upXXXXXXXX",
    "latitude": 43.7764,
    "longitude": 7.4977,
    "preferences": {
      "travaux": true,
      "alertes": true
    }
  }'

Créer une info (admin)

curl -X POST https://urbafix.fr/api/admin/create_info.php \
  -H "Content-Type: application/json" \
  -H "Cookie: PHPSESSID=abc123" \
  -d '{
    "mairie_id": 1,
    "titre": "Marché de Noël",
    "description": "Du 15 au 24 décembre sur la place centrale",
    "type_info": "EVENEMENT",
    "latitude": 43.7750,
    "longitude": 7.5030,
    "rayon_metres": 2000,
    "date_expiration": "2026-12-24 20:00:00"
  }'

Rate Limiting

Endpoint Limite Fenêtre
get_infos.php 100 req 1 minute
register_push_endpoint.php 10 req 1 minute
Endpoints admin 50 req 1 minute

Format d'Erreur

{
  "success": false,
  "error": "Message d'erreur",
  "code": "INVALID_COORDINATES"
}
Code Description
INVALID_COORDINATES Latitude/longitude invalides
MISSING_REQUIRED_FIELD Champ requis manquant
UNAUTHORIZED Session admin requise
NOT_FOUND Information non trouvée
INVALID_STATUS Transition de statut invalide