Files
thetool/scripts/preorder/ofaa-oaid/create-and-confirm-oaid.php
Frank Schubert 8cebb77bf4 OFAA OAID API v2
2026-01-07 14:36:00 +01:00

89 lines
2.4 KiB
PHP
Executable File

#!/usr/bin/php
<?php
require_once __DIR__."/include/config.php";
require_once __DIR__."/include/rest.php";
if(!$access_token) {
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
if(!$access_token) {
die("Error getting access token");
}
}
$headers = [
"Authorization: Bearer $access_token",
"Accept: application/json",
"Content-type: application/json",
];
$content = [
"tenant" => $tenant,
"version" => "v8",
];
//var_dump($content);
if(count($argv) > 1) {
$batch_size = intval($argv[1]);
}
if(!$batch_size) {
die("Batchsize not defined!\n");
}
$c = 0;
$u = 0;
echo "Creating and confirming $batch_size version ".$content['version']." OAIDs for tenant ".$content['tenant']."\n";
for($i = 0; $i < $batch_size; $i++) {
$content['customer_reference'] = guidv4();
$output = postRestUrl($ep_request_oaid, $headers, $content, "application/json");
if($output == "__err__401") {
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
$headers = [
"Authorization: Bearer $access_token",
"Accept: application/json",
"Content-type: application/json",
];
$output = postRestUrl($ep_request_oaid, $headers, $content, "application/json");
}
//var_dump($output);exit;
$output_json = json_decode($output);
if(!is_object($output_json)) {
//var_dump($output);
echo "Output not JSON Object\n";
continue;
}
$c++;
$oaid = $output_json->oaid;
//$tenant = $output_json->tenant;
$token = $output_json->token;
$status = $output_json->status;
$customer_reference = $output_json->customer_reference;
//echo "oaid: $oaid, tenant: $tenant, token: $token, status: $status, external_id: $external_id\n";
if($token == "requested") {
$confirm_url = str_replace("{oaid}", $oaid, $ep_confirm_oaid);
$out = patchRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
if($out == "__err__401") {
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
$headers = [
"Authorization: Bearer $access_token",
"Accept: application/json",
"Content-type: application/json",
];
$out = patchRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
}
echo ".";
$u++;
}
}
echo "Created $c, confirmed $u\n";