2015-12-18 4 views

ответ

1

Это пример заказа мониторинга

<?php 
/** 
* Example to order a portal monitoring 
* 
* Important manual pages: 
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Monitoring_Package 
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order 
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder 
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price 
* 
* License <http://sldn.softlayer.com/article/License> 
* Author SoftLayer Technologies, Inc. <[email protected]> 
* 
*/ 
require_once(dirname(__FILE__) . '/SoftLayer/SoapClient.class.php'); 

# Your SoftLayer API username and key. 
$username = 'set me'; 
$key = 'set me'; 


$prices = array 
(
    # This is the price for Monitoring Package - Premium Application 
    2304, 
); 

# Converting our item list into an array of skeleton 
# SoftLayer_Product_Item_Price objects. These objects contain much more than 
# ids, but SoftLayer's ordering system only needs the price's id to know what 
# you want to order. 
$orderPrices = array(); 

foreach ($prices as $priceId){ 
    $price = new stdClass(); 
    $price->id = $priceId; 
    $orderPrices[] = $price; 
} 


$packageId = 0; # The packageId for order monitoring packages is 0 
$quantity = 0; 
$sendQuoteEmailFlag = false; 
$useHourlyPricing = true; 


# Building a skeleton SoftLayer_Virtual_Guest object to model the Id 
# of the virtual guest where you want add the monitoring package 
$virtualGuests = new stdClass(); 
$virtualGuests->id = 13106845; 
$orderVirtualGuest = array 
(
    $virtualGuests 
); 

$configurationTemplateGroups = new stdClass(); 
$configurationTemplateGroups->id = 41; # Premiun Monitoring Package - Linux 
$orderConfigurationTemplateGroups = array 
(
    $configurationTemplateGroups 
); 



# Build a SoftLayer_Container_Product_Order_Monitoring_Package object containing 
# the order you wish to place. 
$orderContainer = new stdClass(); 
$orderContainer->packageId   = $packageId; 
$orderContainer->prices    = $orderPrices; 
$orderContainer->quantity   = $quantity; 
$orderContainer->sendQuoteEmailFlag = $sendQuoteEmailFlag; 
$orderContainer->useHourlyPricing = $useHourlyPricing; 
$orderContainer->virtualGuests  = $orderVirtualGuest; 
$orderContainer->configurationTemplateGroups  = $orderConfigurationTemplateGroups; 

# Create a SoftLayer API client object 
$softLayer_product_order = SoftLayer_SoapClient::getClient('SoftLayer_Product_Order', null, $username, $key); 

# Place the order for the new server. 
try { 
    # Re-declare the order template as a SOAP variable, so the SoftLayer 
    # ordering system knows what type of order you're placing. 
    $orderTemplate = new SoapVar 
    (
     $orderContainer, 
     SOAP_ENC_OBJECT, 
     'SoftLayer_Container_Product_Order_Monitoring_Package', 
     'http://api.service.softlayer.com/soap/v3/' 
    ); 

    /** 
    * verifyOrder() will check your order for errors. Replace this with a call 
    * to placeOrder() when you're ready to order. Both calls return a receipt 
    * object that you can use for your records. 
    * 
    * Once your order is placed it'll go through SoftLayer's approval and 
    * provisioning process. When it's done you'll have a new 
    * item ready to use. 
    */ 
    $receipt = $softLayer_product_order->verifyOrder($orderTemplate); 
    print_r($receipt); 
} catch (Exception $e) { 
    echo 'Unable to place monitoring order: ' . $e->getMessage(); 
} 

Чтобы получить идентификаторы цены товара после запроса REST может помочь вам:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Package/0/getItemPrices?objectMask=mask[id,categories,locationGroupId,item[id,keyName,description],pricingLocationGroup[locations[id, name, longName]]]&objectFilter={ "itemPrices": {  "categories": {  "categoryCode": {   "operation": "monitoring_package"  }  } } } 
+0

Спасибо mcruz. – mnnmountain

 Смежные вопросы

  • Нет связанных вопросов^_^