如何获取 softalyer orderItem 的标识符

How to get identifier for a softalyer orderItem

有一些计费项目,例如:"categoryCode":"guest_disk1" 或 "categoryCode":"gateway_resource_group"。如何识别此资源属于哪个父服务器?或者如何区分同一类别的 2 个资源。就像我们使用主机名识别 2 个服务器一样。我不想使用 "id" 作为标识符。我尝试使用 parentId 和 parent 但我总是将所有资源都设置为 null。

如果“ParentId”为null,请看resourceTableId 属性,里面会有你需要的item_id(resourceTableId:SoftLayer的唯一标识符与发票项目关联的服务。参考:SoftLayer_Billing_Invoice_Item),

例如执行这个请求时:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Account/getNextInvoiceTopLevelBillingItems?objectFilter={   "nextInvoiceTopLevelBillingItems": {     "orderItem": {       "order": {         "id": {           "operation": 5874669         }       }     }   } }&objectMask=mask[id,categoryCode, item, parentId,orderItem[item],invoiceItems[id,resourceTableId,categoryCode,description,billingItemId],children[parentId,categoryCode,orderItem[id,description,order.id]]]
Method: GET

Where `”5874669”` is the orderId

我的回复是:

[
  {
    "categoryCode": "guest_core",
    "id": 70751841,
    "parentId": null,
    "children": [
      {
        "categoryCode": "ram",
        "parentId": 70751841,
        "orderItem": {
          "description": "8 GB",
          "id": 92196283,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "remote_management",
        "parentId": 70751841,
        "orderItem": {
          "description": "Reboot / Remote Console",
          "id": 92196285,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "port_speed",
        "parentId": 70751841,
        "orderItem": {
          "description": "100 Mbps Public & Private Network Uplinks",
          "id": 92196287,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "public_port",
        "parentId": 70751841,
        "orderItem": {
          "description": "100 Mbps Public Uplink",
          "id": 92196289,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "service_port",
        "parentId": 70751841,
        "orderItem": {
          "description": "100 Mbps Private Uplink",
          "id": 92196291,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "bandwidth",
        "parentId": 70751841,
        "orderItem": {
          "description": "0 GB Bandwidth",
          "id": 92196293,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "pri_ip_addresses",
        "parentId": 70751841,
        "orderItem": {
          "description": "1 IP Address",
          "id": 92196295,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "guest_disk0",
        "parentId": 70751841,
        "orderItem": {
          "description": "25 GB (SAN)",
          "id": 92196297,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "os",
        "parentId": 70751841,
        "orderItem": {
          "description": "Ubuntu Linux 14.04 LTS Trusty Tahr - Minimal Install (64 bit)",
          "id": 92196299,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "monitoring",
        "parentId": 70751841,
        "orderItem": {
          "description": "Host Ping",
          "id": 92196301,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "notification",
        "parentId": 70751841,
        "orderItem": {
          "description": "Email and Ticket",
          "id": 92196303,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "response",
        "parentId": 70751841,
        "orderItem": {
          "description": "Automated Notification",
          "id": 92196305,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "vpn_management",
        "parentId": 70751841,
        "orderItem": {
          "description": "Unlimited SSL VPN Users & 1 PPTP VPN User per account",
          "id": 92196307,
          "order": {
            "id": 5874669
          }
        }
      },
      {
        "categoryCode": "vulnerability_scanner",
        "parentId": 70751841,
        "orderItem": {
          "description": "Nessus Vulnerability Assessment & Reporting",
          "id": 92196309,
          "order": {
            "id": 5874669
          }
        }
      }
    ],
    "invoiceItems": [
      {
        "billingItemId": 70751841,
        "categoryCode": "guest_core",
        "description": "4 x 2.0 GHz Cores",
        "id": 229216475,
        "resourceTableId": 13102629
      },
      {
        "billingItemId": 70751841,
        "categoryCode": "guest_core",
        "description": "4 x 2.0 GHz Cores",
        "id": 236371529,
        "resourceTableId": 13102629
      },
      {
        "billingItemId": 70751841,
        "categoryCode": "guest_core",
        "description": "4 x 2.0 GHz Cores",
        "id": 254309359,
        "resourceTableId": 13102629
      },
      {
        "billingItemId": 70751841,
        "categoryCode": "guest_core",
        "description": "4 x 2.0 GHz Cores",
        "id": 227147491,
        "resourceTableId": null
      },
      {
        "billingItemId": 70751841,
        "categoryCode": "guest_core",
        "description": "4 x 2.0 GHz Cores",
        "id": 245530073,
        "resourceTableId": 13102629
      },
      {
        "billingItemId": 70751841,
        "categoryCode": "guest_core",
        "description": "4 x 2.0 GHz Cores",
        "id": 263996519,
        "resourceTableId": 13102629
      },
      {
        "billingItemId": 70751841,
        "categoryCode": "guest_core",
        "description": "4 x 2.0 GHz Cores",
        "id": 284422451,
        "resourceTableId": 13102629
      },
      {
        "billingItemId": 70751841,
        "categoryCode": "guest_core",
        "description": "4 x 2.0 GHz Cores",
        "id": 274920353,
        "resourceTableId": 13102629
      }
    ],
    "item": {
      "capacity": "4",
      "description": "4 x 2.0 GHz Cores",
      "id": 859,
      "itemTaxCategoryId": 166,
      "keyName": "GUEST_CORES_4",
      "softwareDescriptionId": null,
      "units": "CORE",
      "upgradeItemId": null,
      "itemCategory": {
        "categoryCode": "guest_core",
        "id": 80,
        "name": "Computing Instance",
        "quantityLimit": 20
      },
      "totalPhysicalCoreCount": 4
    },
    "orderItem": {
      "categoryCode": "guest_core",
      "description": "4 x 2.0 GHz Cores",
      "domainName": "mesos.maceacs.com",
      "hostName": "2-master-1712",
      "hourlyRecurringFee": "0",
      "id": 92196281,
      "itemId": 859,
      "itemPriceId": "52135",
      "laborAfterTaxAmount": "0",
      "laborFee": "0",
      "laborFeeTaxRate": "0",
      "laborTaxAmount": "0",
      "oneTimeAfterTaxAmount": "0",
      "oneTimeFee": "0",
      "oneTimeFeeTaxRate": "0",
      "oneTimeTaxAmount": "0",
      "parentId": null,
      "promoCodeId": null,
      "quantity": null,
      "recurringAfterTaxAmount": "0",
      "recurringFee": "0",
      "recurringTaxAmount": "0",
      "setupAfterTaxAmount": "0",
      "setupFee": "0",
      "setupFeeDeferralMonths": 12,
      "setupFeeTaxRate": "0",
      "setupTaxAmount": "0",
      "item": {
        "capacity": "4",
        "description": "4 x 2.0 GHz Cores",
        "id": 859,
        "itemTaxCategoryId": 166,
        "keyName": "GUEST_CORES_4",
        "softwareDescriptionId": null,
        "units": "CORE",
        "upgradeItemId": null,
        "itemCategory": {
          "categoryCode": "guest_core",
          "id": 80,
          "name": "Computing Instance",
          "quantityLimit": 20
        },
        "totalPhysicalCoreCount": 4
      },
      "order": {
        "id": 5874669
      }
    }
  }
]

在此响应中显示与 orderId 关联的所有项目。

第一部分:

[
  {
    "categoryCode": "guest_core",
    "id": 70751841,
    "parentId": null,
    "children": [
      {
        "categoryCode": "ram",
        "parentId": 70751841,
        "orderItem": {
          "description": "8 GB",
          "id": 92196283,
          "order": {
            "id": 5874669
          }
        }
      },
      ....

我们注意到这个 "categoryCode": "guest_core" 没有“parentId”("parentId":null)。这意味着该项目是该订单的父项。

但是如何识别这个商品的id呢?

嗯,在invoiceItems部分有一个属性叫做'resourceTableId',这是父项的id。我的意思是:"resourceTableId"= 13102629 是我的 Virtual Guest

id
 "invoiceItems": [
      {
        "billingItemId": 70751841,
        "categoryCode": "guest_core",
        "description": "4 x 2.0 GHz Cores",
        "id": 229216475,
        "resourceTableId": 13102629
      },

Children section 中将显示与我的订单关联的其他项目,我们可以在其中注意到它们的 parentId = null。