【发布时间】:2017-10-03 09:54:57
【问题描述】:
【问题讨论】:
-
这是一个很好的起点:stackoverflow.com/questions/35126098/…
标签: api ip-address ibm-cloud-infrastructure subnet
【问题讨论】:
标签: api ip-address ibm-cloud-infrastructure subnet
如需提交上述订单信息,您需要在订单中填写参数"itemCategoryQuestionAnswers",该参数可以在Container_Product_Order_Virtual_Guest和Container_Product_Order_Hardware_Server等数据类型中找到
以下是用于 REST 的 JSON 示例:
"itemCategoryQuestionAnswers":[
{
"answer": "2",
"categoryId": 14,
"questionId": 14
},
{
"answer": "4",
"categoryId": 14,
"questionId": 15
}
]
上面的例子属于表格中的前两个问题。如您所见,需要知道 categoryId 和 questionId 参数的 id。请按照以下步骤操作。
类别 ID
作为greyhoundforty评论你,链接SoftLayer API: Ordering Subnet 是一个很好的起点。在该页面上mcruz 显示了如何执行方法Product_Item_Category::getSubnetCategories。该方法返回如下内容:
{
"categoryCode": "global_ipv6",
"id": 331,
"name": "Global IPv6",
"quantityLimit": 0
},
{
"categoryCode": "sec_ip_addresses",
"id": 14,
"name": "Public Secondary IP Addresses",
"quantityLimit": 0
},
在这种情况下,categoryId 为 14 类别 “公共辅助 IP 地址”。
问题ID
要获得与类别“sec_ip_addresses”相关的所有问题,您可以使用Product_Item_Category::getQuestions 或Product_Item_Category::getQuestionReferences 方法。在这种情况下,我将向您展示如何执行 getQuestionReferences 方法:
https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Item_Category/14/getQuestionReferences?objectMask=[question]
Method: GET
它应该返回如下内容:
{
"id": 61,
"questionId": 14,
"required": true,
"question": {
"description": "The number of IP addresses expected to be used within the next 30 days.",
"id": 14
}
},
{
"id": 62,
"questionId": 15,
"required": true,
"question": {
"description": "The number of IP addresses expected to be used within the next 12 months.",
"id": 15
}
},
现在您可以知道表单中每个问题的questionId。
使用辅助公共 IP 地址订购虚拟访客
下面是一个在 REST 中使用辅助 IP 地址和表单中的两个第一个问题订购虚拟访客的示例。
注意:不要忘记更改[用户名]、[apikey]、价格等id 与您自己的数据
https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder
Method: POST
Body JSON:
{
"parameters":[
{
"complexType": "SoftLayer_Container_Product_Order_Virtual_Guest",
"packageId": 46,
"location": "AMSTERDAM",
"quantity": 1,
"prices":[
{"id":14640},
{"id":11644},
{"id":9205},
{"id":22272},
{"id":52231},
{"id":21},
{"id":2202},
{"id":13945},
{"id":55},
{"id":57},
{"id":58},
{"id":420},
{"id":418},
{"id":22}
],
"virtualGuests":[
{
"hostname": "test",
"domain": "example.com"
}
],
"itemCategoryQuestionAnswers":[
{
"answer": "2",
"categoryId": 14,
"questionId": 14
},
{
"answer": "4",
"categoryId": 14,
"questionId": 15
}
]
}
]
}
我不知道您使用的是什么 REST 客户端,但我能够在 REST 客户端从 Firefox 中重现您的问题,在其他 REST 客户端(如 Insomnia)中我只是遇到错误。
基本上,您得到的响应是空的,因为您的 JSON 结构有一些错误。首先,body 中的所有数据都需要放入 "parameters" 对象中,请查看上面的示例。其次,"sshKeyIds" 的值需要用双引号括起来,因为它是一个字符串。最后,我建议你将所有对象和字符串值放在双引号中,因为它是JSON标准格式,你可以在jQuery.parseJSON single quote vs double quote和http://www.json.org/中验证这些信息。
重要提示:在使用 placeOrder 方法之前,我建议您先执行 verifyOrder。当您准备好订购时,只需在 URL 请求中通过 placeOrder 更改 verifyOrder。
我将您的请求修改如下
https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder
Method: POST
Body in JSON format:
{
"parameters":[
{
"complexType" : "SoftLayer_Container_Product_Order_Virtual_Guest",
"location" : "449604",
"packageId" : 46,
"quantity" : 1,
"useHourlyPricing" : true,
"virtualGuests" : [
{
"domain" : "aaa.com",
"hostname" : "sshkey_07"
}
],
"sshKeys" : [
{ "sshKeyIds" : ["620913L"] }
],
"prices" : [
{"id" : 1644 },
{"id" : 2202 },
{"id" : 2259 },
{"id" : 273 },
{"id" : 1640 },
{"id" : 17442},
{"id" : 905 },
{"id" : 21 },
{"id" : 57 },
{"id" : 55 },
{"id" : 58 },
{"id" : 420 },
{"id" : 418 },
{"id" : 22 },
{"id" : 1800 }
],
"itemCategoryQuestionAnswers" : [{
"answer" : "4",
"questionId" : 14,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "4",
"questionId" : 15,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "aaaa",
"questionId" : 16,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "allesa",
"questionId" : 9,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "product manager",
"questionId" : 10,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "xxx@mail.com",
"questionId" : 11,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "xxxxxxxxx",
"questionId" : 12,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "1",
"questionId" : 13,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}
]
}
]
}
如果您有任何疑问或需要进一步帮助,请告诉我。
【讨论】: