Zefix_search/api/index.php

66 lines
1.3 KiB
PHP
Raw Normal View History

2023-08-17 19:08:24 +02:00
<?php
2023-08-17 21:38:35 +02:00
//include 'env_vars.php';
//$username = getenv("username");
//$password = getenv("password");
$username = "username";
$password = "password";
// API endpoint
$apiUrl = 'https://www.zefix.admin.ch/ZefixPublicREST/apicompany/search';
// Request data
$data = array(
"name" => "Silias KLG",
"legalFormId" => 4,
"legalFormUid" => "0107",
"registryOfCommerceId" => 36,
"legalSeatId" => 623,
"canton" => "BE",
"activeOnly" => true
);
// Headers
$headers = array(
"apiKey: mykey"
);
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute cURL session and get the response
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
// Close cURL session
curl_close($ch);
// Output the API response
echo $response;
?>
// Close cURL
curl_close($ch);
// Process the Zefix response and construct your own response
// ...
$constructed_response = $response;
// Send the response back to the client
header('Content-Type: application/json');
echo $constructed_response;
2023-08-17 19:08:24 +02:00
?>