How to order snapshot space from Block Storage using Rest API

74 Views Asked by At

I'm trying to place order but some error came Rest API: https://api.softlayer.com/rest/v3.1/SoftLayer_Product_Order/placeOrder

BODY: { "parameters": [ { "complexType": "SoftLayer_Container_Product_Order_Network_Storage_Enterprise_SnapshotSpace", "packageId": 240, "prices": [ { "id": 201527 } ], "volumeId": 200326976 } ] }

Response: {"error":"The price for 20 GB Storage Space (#201527) is not valid for location ams01.","code":"SoftLayer_Exception_Public"}

2

There are 2 best solutions below

2
Daniel Cabero On

Try to use this body

 {
   "parameters":[
      {
         "complexType":"SoftLayer_Container_Product_Order_Network_Storage_Enterprise",
         "location":"AMSTERDAM",
         "quantity":1,
         "packageId":240,
         "prices":[
            {"id": 45098},      # Block Storage         keyName: storage_block
            {"id": 45058},      # Endurance Storage     keyName: storage_service_enterprise
            {"id": 45138},      # 20 GB Storage Space   keyName: performance_storage_space
            {"id": 45088},      # 4 IOPS per GB         keyName: storage_tier_level
            {"id": 46140}       # 5 GB Storage Space    keyName: storage_snapshot_space
         ],
         "osFormatType":{
            "keyName":"LINUX"
         }
      }
   ]
}

references

https://sldn.softlayer.com/python/order_endurance_storage/ https://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Storage_Object/ https://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getAllObjects/ https://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices/

2
german eduardo On

An error like a specific price is not valid for location, usually means that this item price is not valid for one specific location, so in order to fix your order, you can try to use standard prices, which can be used with any location when ordering.

In a SoftLayer_Product_Item_Price datatype, if "locationGroupId" is null, the price is considered a standard price. On the other hand, you are using 201527 price id, wich item "keyName" is "20_GB_PERFORMANCE_STORAGE_SPACE", then knowing these values you can build an object filter as below:

 objectFilter={
      "itemPrices": {
        "locationGroupId": {
          "operation": "is null"
        },
        "item": {
          "keyName": {
            "operation": "20_GB_PERFORMANCE_STORAGE_SPACE"
          }
        }
      }
    }

and you can retrieval all standard prices by using a rest API call like:

https://api.softlayer.com/rest/v3.1/SoftLayer_Product_Package/240/getItemPrices?objectFilter={"itemPrices":{"locationGroupId":{"operation":"is null"},"item":{"keyName": { "operation" : "20_GB_PERFORMANCE_STORAGE_SPACE"}}}}&objectMask=mask[id,item[keyName,description],locationGroupId]

response example:

[
    {
        "id": 46659,
        "locationGroupId": null,
        "item": {
            "description": "20 GB Storage Space",
            "keyName": "20_GB_PERFORMANCE_STORAGE_SPACE"
        }
    },
    {
        "id": 45128,
        "locationGroupId": null,
        "item": {
            "description": "20 GB Storage Space",
            "keyName": "20_GB_PERFORMANCE_STORAGE_SPACE"
        }
    },

For instance, try to use a standard price retrieved above in your JSON body, also you can just check it by using the verify method:

POST:

https://api.softlayer.com/rest/v3.1/SoftLayer_Product_Order/verifyOrder

BODY:

{
  "parameters": [
    {
      "complexType": "SoftLayer_Container_Product_Order_Network_Storage_Enterprise_SnapshotSpace",
      "packageId": 240,
      "prices": [
        {
          "id": 45128
        }
      ],
      "quantity": 1,
      "location": "AMSTERDAM",
      "volumeId": 200326976
    }
  ]
}