You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PHP调用OCCRP Aleph API时持续报错“No schema is specified for the query.”

Fixing "No schema is specified for the query." Error with OCCRP Aleph API in PHP

The error you're hitting is directly tied to your API request's query parameter format—you're missing a required entity schema specification, and there's an issue with quote escaping in your URL. Let's break this down and fix it step by step:

1. Why the Error Occurs

The OCCRP Aleph API requires you to define what type of entity you're searching for (like companies, people, or organizations) using the schema field in your query. Your current request only filters by title:bank but doesn't tell the API which category of entities to pull. The stats endpoint works because it doesn't enforce this strict schema requirement.

On top of that, your URL uses HTML-escaped quotes (") which are unnecessary here and likely causing parsing issues for the API.

2. Corrected Query Syntax

You need to add a schema filter to your q parameter. Here are common valid examples:

  • Search for companies with "bank" in their title: q=schema:Company AND title:bank
  • Search for any entity type (less precise, but functional) with "bank" in their title: q=title:bank AND schema:*
  • Match the exact phrase "bank" in a company's title: q=schema:Company AND title:"bank"

3. Fixed PHP Code

Here's your updated code with a clean, valid URL and proper quote handling (no HTML escaping needed in the PHP string):

// Use a specific schema and clean query syntax
$url = 'https://aleph.occrp.org/api/2/entities?q=schema:Company%20AND%20title:bank';
$ch = curl_init();
$headeroptions = array(
    'Accept: application/json',
    'Content-Type: application/json',
    'Authorization: ApiKey 363af1e2b03b41c6b3adc604956e2f66'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headeroptions);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
$array = json_decode($data, true);
var_dump($array);

Key Fix Notes:

  • We replaced the HTML-escaped quotes with a standard Lucene-style query that includes schema:Company.
  • Spaces in the query are URL-encoded as %20; for dynamic queries, use PHP's urlencode() to avoid manual encoding:
    $query = 'schema:Company AND title:"bank"';
    $url = 'https://aleph.occrp.org/api/2/entities?q=' . urlencode($query);
    

4. Valid Schema Options

Common entity schemas supported by Aleph include schema:Company, schema:Person, schema:Organization, and schema:LegalEntity. Using a narrow schema will make your query faster and more accurate.

内容的提问来源于stack exchange,提问作者Danny Scheers

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 20:12:50