Commit efb628e5 authored by Jean-Baptiste Oellers's avatar Jean-Baptiste Oellers
Browse files

API SIRENE recherche avec espace

parent e40480b5
Loading
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -204,7 +204,17 @@ class SiretService implements UseEntityManager, UseOscarConfigurationService

      if ($etablissement == NULL && $recherche_par_api_disponible) {
        $curl = curl_init();
        $url = "https://api.insee.fr/api-sirene/3.11/siret?q=-codePaysEtrangerEtablissement:*%20AND%20%28denominationUniteLegale:*" . urlencode($denominationLegale) . '*%20OR%20nomUniteLegale:*' . urlencode($denominationLegale) . '*%29';

        $denominationsLegales = preg_split("/ /", $denominationLegale);
        $query = '';
        foreach ($denominationsLegales as $d) {
          if ($d == '') {
            continue;
          }
          $query .= "%20AND%20%28denominationUniteLegale:*" . urlencode($d) . '*%20OR%20nomUniteLegale:*' . urlencode($d) . '*%29';
        }

        $url = "https://api.insee.fr/api-sirene/3.11/siret?q=-codePaysEtrangerEtablissement:*" . $query;
        curl_setopt($curl, CURLOPT_URL, $url);
        $headers = [
          'X-INSEE-Api-Key-Integration: ' . $cleAPI,
@@ -218,7 +228,7 @@ class SiretService implements UseEntityManager, UseOscarConfigurationService
          if ($httpcode == 404 && $result !== FALSE) {
            $retour_api = json_decode($result);
            if (str_starts_with($retour_api->header->message, 'Aucun élément trouvé pour')) {
              throw new OscarSiretException("L'API SIRENE n'a pas trouvé ce SIRET");
              throw new OscarSiretException("L'API SIRENE n'a pas trouvé cette dénomination légale");
            }
          }
          throw new OscarSiretException("Erreur lors de l'appel à l'API SIRENE. Code HTTP : " . $httpcode . " Retour: " . $result);