KlausK wrote: ↑Thu 27. Jan 2022, 14:26
Die Daten liegen alle tabellarisch vor.
In KH sind bisher nur ich selbst und ein TestUser angelegt.
Also muss User und. DB angelget werden?
Ich hatte letzte Woche was für einen anderen User geschrieben, das könnte man wohl mit etwas Änderung übernehmen.
Code: Select all
<?php
function sendCommand($body)
{
$serverName = 'https://keyhelp/api/v2/clients/';
$apiKey = 'uhTKKvRb.[..]9TrxCCE9d';
$apiResult = [
'response' => 'error'
];
$curl = curl_init();
curl_setopt($curl, option: CURLOPT_URL, value: $serverName);
curl_setopt($curl, option: CURLOPT_RETURNTRANSFER, value: true);
curl_setopt($curl, option: CURLOPT_POST, value: true);
curl_setopt($curl, option: CURLOPT_HTTPHEADER, value: ["X-API-Key:$apiKey"]);
curl_setopt($curl, option: CURLOPT_POSTFIELDS, value: json_encode($body));
if ($resultJSON = curl_exec($curl)) {
$httpResponse = curl_getinfo($curl)['http_code'];
$apiResult = json_decode($resultJSON);
switch($httpResponse) {
case 200:
// no error
break;
case 201:
// user created
$apiResult = [
'userid' => $apiResult->id
];
break;
case 400:
$apiResult = [
'code' => '400 Bad Request',
'error' => $apiResult->message
];
break;
case 401:
$apiResult = [
'error' => 'Missing or wrong API Key'
];
break;
default:
$apiResult = [
'error' => 'Unhandled error ' . $httpResponse
];
}
} else {
$apiResult = [
'error' => 'Unknown error'
];
}
curl_close($curl);
echo json_encode($apiResult) . PHP_EOL;
}
$ofile = fopen("debug.txt", "w");
$parameter = print_r($_POST, true);
fputs($ofile, $parameter);
fclose($ofile);
$content = [
'username' => $_REQUEST['username'],
'language' => "de",
'email' => "me@example.com",
'password' => "qwertz",
'notes' => "Any comments about this client account.",
'send_login_credentials' => true,
'create_system_domain' => true,
];
sendCommand($content);
Das ist jetzt zur Interaktion mit einem HTML Formular ausgelegt, aber kann mal sicher anpassen, eine CSV zu parsen und dann drüber zu laufen.