使用 PHP 创建带宽池

Creating a Bandwidth Pool with PHP

我正在尝试使用 PHP 创建一个新的带宽池,但我收到关于我的 API 密钥的错误。如果我 运行 任何其他脚本但是使用相同的密钥,它们 return 就好了,这让我觉得我的脚本中的某些东西导致东西被乱序解析:

<?php
require_once './vendor/autoload.php';
$apiUsername = getenv('SOFTLAYER_USERNAME');
$apiKey = getenv('SOFTLAYER_API_KEY');


$template = new stdClass();
$template->accountId = xxxxx;
$template->bandwidthAllotmentTypeId  = 2;
$template->locationGroupId = 1;
$template->name  = 'newBWpoolPHP';
$template->serviceProviderId = 1;

try {
  $client = \SoftLayer\SoapClient::getClient('SoftLayer_Network_Bandwidth_Version1_Allotment', $apiUsername, $apiKey);
  $response = $client->createObject(template);

  print_r($response);

 } catch(Exception $e) {
     echo 'Cannot compute. Error is: ' . $e->getMessage();
}

?>

错误是因为您创建的服务有误,需要满足以下条件:

getClient('serviceName', ObjectID, Username, ApiKey)

在本例中没有 ObjectID,因此您需要将值作为 null 发送。

试试下面的代码:

<?php
    require_once './vendor/autoload.php';
    $apiUsername = getenv('SOFTLAYER_USERNAME');
    $apiKey = getenv('SOFTLAYER_API_KEY');

    $template = new stdClass();
    $template->accountId = 307608;
    $template->bandwidthAllotmentTypeId  = 2;
    $template->locationGroupId = 1;
    $template->name  = 'newBWpoolPHP';

    try {
      $client = \SoftLayer\SoapClient::getClient('SoftLayer_Network_Bandwidth_Version1_Allotment', null, $apiUsername, $apiKey);
      $response = $client->createObject($template);

      print_r($response);

     } catch(Exception $e) {
         echo 'Cannot compute. Error is: ' . $e->getMessage();
    }

    ?>