softlayer api: 如何在订购时订购 Public 次要 IP 地址?
softlayer api: How to order Public Secondary IP Addresses when I ordering?
我想在订购时订购 Public 个辅助 IP 地址。以及如何通过 softlayer api 提交这些订单信息?
提交上述订单信息,您需要在下单时填写参数"itemCategoryQuestionAnswers",该参数可以在Container_Product_Order_Virtual_Guest and Container_Product_Order_Hardware_Server等数据类型中找到]
下面是 JSON 中用于 REST 的示例:
"itemCategoryQuestionAnswers":[
{
"answer": "2",
"categoryId": 14,
"questionId": 14
},
{
"answer": "4",
"categoryId": 14,
"questionId": 15
}
]
上面的例子属于表格中的前两个问题。可以看到,需要知道categoryId和questionId参数的id。按照以下步骤操作。
类别ID
作为greyhoundforty comment you, the link SoftLayer API: Ordering Subnet
是一个很好的起点。在那个页面 mcruz shows how to execute the method Product_Item_Category::getSubnetCategories。方法 returns 是这样的:
{
"categoryCode": "global_ipv6",
"id": 331,
"name": "Global IPv6",
"quantityLimit": 0
},
{
"categoryCode": "sec_ip_addresses",
"id": 14,
"name": "Public Secondary IP Addresses",
"quantityLimit": 0
},
在这种情况下,类别 "Public Secondary IP Addresses".
的 categoryId 为 14
问题ID
要获取与类别 "sec_ip_addresses" 相关的所有问题,您可以使用方法 Product_Item_Category::getQuestions or Product_Item_Category::getQuestionReferences。在这种情况下,我将向您展示如何执行 getQuestionReferences 方法:
https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Item_Category/14/getQuestionReferences?objectMask=[question]
Method: GET
应该returns像这样:
{
"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。
使用辅助 Public 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 客户端中重现您的问题,在其他 REST 客户端(例如 Insomnia 中我只是遇到错误。
基本上,您得到的响应是空的,因为您的 JSON 结构有一些错误。首先,body 中的所有数据都需要放入 "parameters" 对象中,请查看上面的示例。其次,"sshKeyIds" 的值需要用双引号引起来,因为它是一个字符串。最后推荐大家将所有对象和字符串值都放在双引号内,因为是JSON标准格式,你可以在jQuery.parseJSON single quote vs double quote and 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
}
]
}
]
}
如果您有任何疑问或需要进一步的帮助,请告诉我。
我想在订购时订购 Public 个辅助 IP 地址。以及如何通过 softlayer api 提交这些订单信息?
提交上述订单信息,您需要在下单时填写参数"itemCategoryQuestionAnswers",该参数可以在Container_Product_Order_Virtual_Guest and Container_Product_Order_Hardware_Server等数据类型中找到]
下面是 JSON 中用于 REST 的示例:
"itemCategoryQuestionAnswers":[
{
"answer": "2",
"categoryId": 14,
"questionId": 14
},
{
"answer": "4",
"categoryId": 14,
"questionId": 15
}
]
上面的例子属于表格中的前两个问题。可以看到,需要知道categoryId和questionId参数的id。按照以下步骤操作。
类别ID
作为greyhoundforty comment you, the link SoftLayer API: Ordering Subnet 是一个很好的起点。在那个页面 mcruz shows how to execute the method Product_Item_Category::getSubnetCategories。方法 returns 是这样的:
{
"categoryCode": "global_ipv6",
"id": 331,
"name": "Global IPv6",
"quantityLimit": 0
},
{
"categoryCode": "sec_ip_addresses",
"id": 14,
"name": "Public Secondary IP Addresses",
"quantityLimit": 0
},
在这种情况下,类别 "Public Secondary IP Addresses".
的 categoryId 为 14问题ID
要获取与类别 "sec_ip_addresses" 相关的所有问题,您可以使用方法 Product_Item_Category::getQuestions or Product_Item_Category::getQuestionReferences。在这种情况下,我将向您展示如何执行 getQuestionReferences 方法:
https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Item_Category/14/getQuestionReferences?objectMask=[question]
Method: GET
应该returns像这样:
{
"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。
使用辅助 Public 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 客户端中重现您的问题,在其他 REST 客户端(例如 Insomnia 中我只是遇到错误。
基本上,您得到的响应是空的,因为您的 JSON 结构有一些错误。首先,body 中的所有数据都需要放入 "parameters" 对象中,请查看上面的示例。其次,"sshKeyIds" 的值需要用双引号引起来,因为它是一个字符串。最后推荐大家将所有对象和字符串值都放在双引号内,因为是JSON标准格式,你可以在jQuery.parseJSON single quote vs double quote and 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
}
]
}
]
}
如果您有任何疑问或需要进一步的帮助,请告诉我。