Integrations > APIs. * The API key defines the tenant context. */ $apiBase='https://app.fenzon.com/api.php'; $apiKey=getenv('FENZON_API_KEY')?:'YOUR_API_KEY'; if($apiKey==='YOUR_API_KEY'){throw new RuntimeException('Set FENZON_API_KEY or replace YOUR_API_KEY before running this file.');} function fenzonRequest(string $method,string $url,array $headers=[],?array $body=null):array{ $ch=curl_init($url); $requestHeaders=array_merge(['Accept: application/json'],$headers); $options=[ CURLOPT_RETURNTRANSFER=>true, CURLOPT_CUSTOMREQUEST=>$method, CURLOPT_HTTPHEADER=>$requestHeaders, CURLOPT_CONNECTTIMEOUT=>5, CURLOPT_TIMEOUT=>20 ]; if($body!==null){ $json=json_encode($body,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_THROW_ON_ERROR); $requestHeaders[]='Content-Type: application/json'; $options[CURLOPT_HTTPHEADER]=$requestHeaders; $options[CURLOPT_POSTFIELDS]=$json; } curl_setopt_array($ch,$options); $raw=curl_exec($ch); if($raw===false){$error=curl_error($ch);curl_close($ch);throw new RuntimeException('API connection failed: '.$error);} $status=(int)curl_getinfo($ch,CURLINFO_RESPONSE_CODE); curl_close($ch); $data=json_decode($raw,true,512,JSON_THROW_ON_ERROR); if($status<200||$status>=300||isset($data['error'])){$message=$data['error']['message']??('HTTP '.$status);throw new RuntimeException('Fenzon API: '.$message);} return$data; } // 1. Create a Bearer session from the API key. $session=fenzonRequest('POST',$apiBase.'/auth/session',['X-Fenzon-Api-Key: '.$apiKey]); $token=(string)($session['data']['session_token']??$session['data']['token']??''); if($token==='')throw new RuntimeException('The API did not return a session token.'); $auth=['Authorization: Bearer '.$token]; // 2. Optional: read the current runtime schema for a data area. $productSchema=fenzonRequest('GET',$apiBase.'/endpoints/products',$auth); // 3. Read live tenant data. $products=fenzonRequest('GET',$apiBase.'/products?limit=10',$auth); header('Content-Type: text/plain; charset=utf-8'); echo "Products runtime schema\n"; echo "=======================\n"; echo json_encode($productSchema['data']??$productSchema,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); echo "\n\nFirst products\n"; echo "==============\n"; echo json_encode($products['data']??$products,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); echo "\n";