【问题标题】:softlayer api: How to order Public Secondary IP Addresses when I ordering?softlayer api:订购时如何订购公共辅助 IP 地址?
【发布时间】:2017-10-03 09:54:57
【问题描述】:

我想在订购时订购公共辅助 IP 地址。以及如何通过 softlayer api 提交这些订单信息?

【问题讨论】:

标签: api ip-address ibm-cloud-infrastructure subnet


【解决方案1】:

如需提交上述订单信息,您需要在订单中填写参数"itemCategoryQuestionAnswers",该参数可以在Container_Product_Order_Virtual_GuestContainer_Product_Order_Hardware_Server等数据类型中找到

以下是用于 REST 的 JSON 示例:

"itemCategoryQuestionAnswers":[
            {
                "answer": "2",
                "categoryId": 14,
                "questionId": 14
            },
            {
                "answer": "4",
                "categoryId": 14,
                "questionId": 15
            }
        ]

上面的例子属于表格中的前两个问题。如您所见,需要知道 categoryIdquestionId 参数的 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::getQuestionsProduct_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 客户端,但我能够在 REST 客户端从 Firefox 中重现您的问题,在其他 REST 客户端(如 Insomnia)中我只是遇到错误。

基本上,您得到的响应是空的,因为您的 JSON 结构有一些错误。首先,body 中的所有数据都需要放入 "parameters" 对象中,请查看上面的示例。其次,"sshKeyIds" 的值需要用双引号括起来,因为它是一个字符串。最后,我建议你将所有对象和字符串值放在双引号中,因为它是JSON标准格式,你可以在jQuery.parseJSON single quote vs double quotehttp://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
                }
            ]           
        }
    ]
} 

如果您有任何疑问或需要进一步帮助,请告诉我。

【讨论】:

  • 我这样设置参数,但是placeOrder返回itemCategoryQuestionAnswers为空的订单结果。
  • 我可以下单成功,但是返回到'itemCategoryQuestionAnswers'的下单信息也是[]。谢谢你的回复,问候~
  • 对不起,回复晚了,我从昨天开始测试了这个行为,我总是得到相同的结果,当从网页创建虚拟服务器时,所有问题/答案都被保存,但由于某种原因,当它们没有被保存时使用 API(SOAP 或 REST)。我报告了这个问题以便得到解决。修复后我会更新这篇文章。
猜你喜欢
  • 2020-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-03
  • 2018-10-22
  • 1970-01-01
相关资源
最近更新 更多