OFAA OAID API v2
This commit is contained in:
@@ -27,18 +27,17 @@ $headers = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
$confirm_url = str_replace("{oaid}", $oaid, $ep_confirm_oaid);
|
$confirm_url = str_replace("{oaid}", $oaid, $ep_confirm_oaid);
|
||||||
$out = putRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
$out = patchRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
||||||
if($output == "__err__401") {
|
if($out == "__err__401") {
|
||||||
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
|
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
|
||||||
$headers = [
|
$headers = [
|
||||||
"Authorization: Bearer $access_token",
|
"Authorization: Bearer $access_token",
|
||||||
"Accept: application/json",
|
"Accept: application/json",
|
||||||
"Content-type: application/json",
|
"Content-type: application/json",
|
||||||
];
|
];
|
||||||
$out = putRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
$out = patchRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
||||||
$u++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "$oaid_name confirmed.\n";
|
echo "$oaid confirmed.\n";
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ $u = 0;
|
|||||||
echo "Creating and confirming $batch_size version ".$content['version']." OAIDs for tenant ".$content['tenant']."\n";
|
echo "Creating and confirming $batch_size version ".$content['version']." OAIDs for tenant ".$content['tenant']."\n";
|
||||||
|
|
||||||
for($i = 0; $i < $batch_size; $i++) {
|
for($i = 0; $i < $batch_size; $i++) {
|
||||||
$content['external_id'] = guidv4();
|
$content['customer_reference'] = guidv4();
|
||||||
|
|
||||||
$output = postRestUrl($ep_request_oaid, $headers, $content, "application/json");
|
$output = postRestUrl($ep_request_oaid, $headers, $content, "application/json");
|
||||||
if($output == "__err__401") {
|
if($output == "__err__401") {
|
||||||
@@ -61,16 +61,16 @@ for($i = 0; $i < $batch_size; $i++) {
|
|||||||
$c++;
|
$c++;
|
||||||
|
|
||||||
$oaid = $output_json->oaid;
|
$oaid = $output_json->oaid;
|
||||||
$tenant = $output_json->tenant;
|
//$tenant = $output_json->tenant;
|
||||||
$token = $output_json->token;
|
$token = $output_json->token;
|
||||||
$status = $output_json->status;
|
$status = $output_json->status;
|
||||||
$external_id = $output_json->external_id;
|
$customer_reference = $output_json->customer_reference;
|
||||||
|
|
||||||
//echo "oaid: $oaid, tenant: $tenant, token: $token, status: $status, external_id: $external_id\n";
|
//echo "oaid: $oaid, tenant: $tenant, token: $token, status: $status, external_id: $external_id\n";
|
||||||
|
|
||||||
if($token == "requested") {
|
if($token == "requested") {
|
||||||
$confirm_url = str_replace("{oaid}", $oaid, $ep_confirm_oaid);
|
$confirm_url = str_replace("{oaid}", $oaid, $ep_confirm_oaid);
|
||||||
$out = putRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
$out = patchRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
||||||
if($out == "__err__401") {
|
if($out == "__err__401") {
|
||||||
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
|
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
|
||||||
$headers = [
|
$headers = [
|
||||||
@@ -78,7 +78,7 @@ for($i = 0; $i < $batch_size; $i++) {
|
|||||||
"Accept: application/json",
|
"Accept: application/json",
|
||||||
"Content-type: application/json",
|
"Content-type: application/json",
|
||||||
];
|
];
|
||||||
$out = putRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
$out = patchRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
||||||
}
|
}
|
||||||
echo ".";
|
echo ".";
|
||||||
$u++;
|
$u++;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ $client_secret = "6e74e7e8-0cc2-43df-83c2-12937452b916";
|
|||||||
$ep_mgm_credits = $baseurl."/pip/mgm/credits/";
|
$ep_mgm_credits = $baseurl."/pip/mgm/credits/";
|
||||||
$ep_list_oaids = $baseurl."/pip/codes/";
|
$ep_list_oaids = $baseurl."/pip/codes/";
|
||||||
$ep_request_oaid = $baseurl."/pip/codes/";
|
$ep_request_oaid = $baseurl."/pip/codes/";
|
||||||
$ep_confirm_oaid = $baseurl."/pip/codes/{oaid}/token/";
|
$ep_confirm_oaid = $baseurl."/pip/codes/{oaid}/";
|
||||||
|
|
||||||
//$default_scope = ["oaid:mgm:read","oaid:codes:read","oaid:codes:write"];
|
//$default_scope = ["oaid:mgm:read","oaid:codes:read","oaid:codes:write"];
|
||||||
$default_scope = ["read","write"]; // since v2
|
$default_scope = ["read","write"]; // since v2
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$rest_last_api_request_nexturl = "";
|
||||||
|
|
||||||
function fetchAccessToken($oauth_url, $client_id, $client_secret, $scopes = ["oaid:codes:read"]) {
|
function fetchAccessToken($oauth_url, $client_id, $client_secret, $scopes = ["oaid:codes:read"]) {
|
||||||
//echo "called fetchAccessToken $oauth_url\n";
|
//echo "called fetchAccessToken $oauth_url\n";
|
||||||
@@ -30,6 +32,8 @@ function fetchAccessToken($oauth_url, $client_id, $client_secret, $scopes = ["oa
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getRestUrl($url, $headers, $params = [], $debug = false) {
|
function getRestUrl($url, $headers, $params = [], $debug = false) {
|
||||||
|
global $rest_last_api_request_nexturl;
|
||||||
|
|
||||||
//echo "called getRestUrl $url\n";
|
//echo "called getRestUrl $url\n";
|
||||||
$ctx_options = ["http" => [
|
$ctx_options = ["http" => [
|
||||||
"ignore_errors" => true,
|
"ignore_errors" => true,
|
||||||
@@ -49,26 +53,45 @@ function getRestUrl($url, $headers, $params = [], $debug = false) {
|
|||||||
|
|
||||||
$ctx = stream_context_create($ctx_options);
|
$ctx = stream_context_create($ctx_options);
|
||||||
$output = file_get_contents($_url, false, $ctx);
|
$output = file_get_contents($_url, false, $ctx);
|
||||||
|
|
||||||
|
if($debug) {
|
||||||
|
echo $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
$_return = "";
|
||||||
|
$http_status_line = "";
|
||||||
|
|
||||||
foreach($http_response_header as $h_line) {
|
foreach($http_response_header as $h_line) {
|
||||||
$m = [];
|
if($debug) {
|
||||||
|
echo "HEADER: " . trim($h_line) . "\n";
|
||||||
|
}
|
||||||
if(preg_match('/HTTP\/\d+(?:\.\d+) ([245]\d+)/', $h_line, $m)) {
|
if(preg_match('/HTTP\/\d+(?:\.\d+) ([245]\d+)/', $h_line, $m)) {
|
||||||
|
$http_status_line = $h_line;
|
||||||
$response_code = $m[1];
|
$response_code = $m[1];
|
||||||
if(substr($response_code, 0, 1) == "2") {
|
if(substr($response_code, 0, 1) == "2") {
|
||||||
return $output;
|
$_return = $output;
|
||||||
} elseif($response_code == "401") {
|
} elseif($response_code == "401") {
|
||||||
return "__err__401";
|
$_return = "__err__401";
|
||||||
} else {
|
|
||||||
die("getRestUrl():\n$h_line\n$output");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(preg_match('/^Link: .*<([^>]+)>; rel=next/', $h_line, $m)) {
|
||||||
|
$rest_last_api_request_nexturl = $m[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$_return) die("getRestUrl():\n$http_status_line\n$output");
|
||||||
|
return $_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function putRestUrl($url, $headers, $content, $content_type = "application/x-www-form-urlencoded", $follow_location = true, $debug = false) {
|
function putRestUrl($url, $headers, $content, $content_type = "application/x-www-form-urlencoded", $follow_location = true, $debug = false) {
|
||||||
return postRestUrl($url, $headers, $content, $content_type, $follow_location, $debug, 'PUT');
|
return postRestUrl($url, $headers, $content, $content_type, $follow_location, $debug, 'PUT');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function patchRestUrl($url, $headers, $content, $content_type = "application/x-www-form-urlencoded", $follow_location = true, $debug = false) {
|
||||||
|
return postRestUrl($url, $headers, $content, $content_type, $follow_location, $debug, 'PATCH');
|
||||||
|
}
|
||||||
|
|
||||||
function postRestUrl($url, $headers, $content, $content_type = "application/x-www-form-urlencoded", $follow_location = true, $debug = false, $method = "POST") {
|
function postRestUrl($url, $headers, $content, $content_type = "application/x-www-form-urlencoded", $follow_location = true, $debug = false, $method = "POST") {
|
||||||
//echo "called postResturl $url\n";
|
//echo "called postResturl $url\n";
|
||||||
$ctx_options = ["http" => [
|
$ctx_options = ["http" => [
|
||||||
@@ -84,6 +107,9 @@ function postRestUrl($url, $headers, $content, $content_type = "application/x-ww
|
|||||||
if($method == "PUT") {
|
if($method == "PUT") {
|
||||||
$ctx_options["http"]["method"] = "PUT";
|
$ctx_options["http"]["method"] = "PUT";
|
||||||
}
|
}
|
||||||
|
if($method == "PATCH") {
|
||||||
|
$ctx_options["http"]["method"] = "PATCH";
|
||||||
|
}
|
||||||
|
|
||||||
if($content_type == "application/x-www-form-urlencoded") {
|
if($content_type == "application/x-www-form-urlencoded") {
|
||||||
$ctx_options["http"]["content"] = http_build_query($content);
|
$ctx_options["http"]["content"] = http_build_query($content);
|
||||||
|
|||||||
@@ -15,15 +15,24 @@ if(!$access_token) {
|
|||||||
$headers[] = "Accept: application/json";
|
$headers[] = "Accept: application/json";
|
||||||
$headers[] = "Authorization: Bearer $access_token";
|
$headers[] = "Authorization: Bearer $access_token";
|
||||||
|
|
||||||
|
$request_url = $ep_list_oaids;
|
||||||
|
$page_size = 500;
|
||||||
$page = 1;
|
$page = 1;
|
||||||
|
$page_param = ["_page_size" => $page_size];
|
||||||
|
$last_ref = false;
|
||||||
while(1) {
|
while(1) {
|
||||||
$output = getRestUrl($ep_list_oaids, $headers, ["tenant"=> $tenant, "_page" => $page]);
|
if($rest_last_api_request_nexturl) {
|
||||||
|
$request_url = $rest_last_api_request_nexturl;
|
||||||
|
$page_param = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = getRestUrl($request_url, $headers, $page_param);
|
||||||
if($output == "__err__401") {
|
if($output == "__err__401") {
|
||||||
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
|
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
|
||||||
$headers = [];
|
$headers = [];
|
||||||
$headers[] = "Accept: application/json";
|
$headers[] = "Accept: application/json";
|
||||||
$headers[] = "Authorization: Bearer $access_token";
|
$headers[] = "Authorization: Bearer $access_token";
|
||||||
$output = getRestUrl($ep_list_oaids, $headers, ["tenant"=> $tenant, "_page" => $page]);
|
$output = getRestUrl($request_url, $headers, $page_param);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output_values = json_decode($output);
|
$output_values = json_decode($output);
|
||||||
@@ -39,12 +48,14 @@ while(1) {
|
|||||||
|
|
||||||
foreach($output_values as $oaid_obj) {
|
foreach($output_values as $oaid_obj) {
|
||||||
echo $oaid_obj->oaid.";";
|
echo $oaid_obj->oaid.";";
|
||||||
echo $oaid_obj->external_id.";";
|
echo $oaid_obj->customer_reference.";";
|
||||||
echo ";";
|
echo ";";
|
||||||
if($oaid_obj->token != "confirmed") {
|
if($oaid_obj->token != "confirmed") {
|
||||||
file_put_contents( "php://stderr", "; ".$oaid_obj->token );
|
file_put_contents( "php://stderr", "; ".$oaid_obj->token );
|
||||||
}
|
}
|
||||||
echo "\n";
|
echo "\n";
|
||||||
|
$last_ref = $oaid_obj->customer_reference;
|
||||||
|
//$last_ref = $oaid_obj->oaid;
|
||||||
}
|
}
|
||||||
$page++;
|
$page++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user