答案 0 :(得分:1)
要提交上述订单信息,您需要在订单中填写参数" itemCategoryQuestionAnswers" ,该参数可以在Container_Product_Order_Virtual_Guest等数据类型中找到Container_Product_Order_Hardware_Server
以下是JSON for REST的示例:
"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
},
在这种情况下,类别&#34;公共辅助IP地址&#34; 的 categoryId为14 。
<强> QuestionID 强>
要获取与&#34; sec_ip_addresses&#34; 类别相关的所有问题,您可以使用方法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客户端,但是我能够在firefox的RESTclient中重现你的问题,在Insomnia等其他REST客户端中我只是出错了。
基本上,由于您的JSON结构存在一些错误,因此您的响应为空。首先,身体中的所有数据都需要包含在&#34;参数&#34; 对象中,请查看上面的示例。其次,&#34; sshKeyIds&#34; 的值需要是双引号,因为它是一个字符串。最后,我建议您将所有对象和字符串值放入双引号,因为它是JSON标准格式,您可以在jQuery.parseJSON single quote vs double quote和http://www.json.org/中验证此信息。< / p>
重要提示:在使用placeOrder方法之前,我建议您首先执行verifyOrder 。何时,您已准备好订购,只需通过placeOrder在URL请求中更改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
}
]
}
]
}
如果您有任何疑问或需要进一步帮助,请与我联系。