softlayer api:订购时如何订购公共二级IP地址? [英] softlayer api: How to order Public Secondary IP Addresses when I ordering?

查看:57
本文介绍了softlayer api:订购时如何订购公共二级IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to order Public Secondary IP Addresses when I ordering. And How to submit these order infomation by softlayer api ?

推荐答案

要提交上述订单信息,您需要在订单过程中填写参数"itemCategoryQuestionAnswers" ,该参数可以找到的数据类型为 Container_Product_Order_Virtual_Guest

To submit the order information described above, you need to fill the parameter "itemCategoryQuestionAnswers" during the order, that parameter can be found in datatypes like Container_Product_Order_Virtual_Guest and Container_Product_Order_Hardware_Server

以下是REST的JSON示例:

Below is an example in JSON for REST:

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

上面的示例属于表格中的前两个问题.如您所见,有必要知道 categoryId questionId 参数的ID.请按照以下步骤操作.

The example above belongs to the first two questions in the form. As you can see, it is necessary to know the id of categoryId and questionId parameters. Follow the steps below.

类别ID

greyhoundforty 评论您时,链接 mcruz 显示如何执行方法

As greyhoundforty comment you, the link SoftLayer API: Ordering Subnet is a good starting point. On that page mcruz shows how to execute the method Product_Item_Category::getSubnetCategories. The method returns some thing like this:

    {
        "categoryCode": "global_ipv6",
        "id": 331,
        "name": "Global IPv6",
        "quantityLimit": 0
    },
    {
        "categoryCode": "sec_ip_addresses",
        "id": 14,
        "name": "Public Secondary IP Addresses",
        "quantityLimit": 0
    },

在这种情况下,类别公共辅助IP地址" categoryId为14 .

On this case the categoryId is 14 for category "Public Secondary IP Addresses".

问题ID

要获取与类别"sec_ip_addresses" 相关的所有问题,可以使用方法 Product_Item_Category :: getQuestions Product_Item_Category :: getQuestionReferences .在这种情况下,我将向您展示如何执行 getQuestionReferences 方法:

To get all questions related to the category "sec_ip_addresses" you can use the method Product_Item_Category::getQuestions or Product_Item_Category::getQuestionReferences. On this case I'll show you how execute getQuestionReferences method:

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 .

Now you can know the questionId of each question in the form.

使用辅助公共IP地址订购虚拟访客

下面是REST中的一个示例,该示例订购具有次要IP地址和表单中的两个第一个问题的虚拟访客.

Below is an example in REST to order a virtual guest with a secondary ip address and two first questions in the form.

注意:不要忘记更改 [用户名] [apikey] 价格以及其他具有您自己的数据的ID

Note: Don't forget change [username], [apikey], prices, and other ids with your own data

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客户端(如

About your REST structure

I don't know what REST client you are using, but I was able to reproduce your issue in a RESTclient from firefox, in other REST clients like Insomnia I'm just getting errors.

基本上,由于JSON结构存在一些错误,因此您得到的响应为空.首先,主体中的所有数据都必须放入"parameters" 对象中,请查看上面的示例.其次,"sshKeyIds" 的值必须用双引号引起来,因为它是一个字符串.最后,我建议您将所有对象和字符串值放入双引号中,因为它是JSON标准格式,因此您可以在 http://www.json.org/.

Basically, you are getting empty response because your JSON structure have some mistakes. First, all data in body needs to be into "parameters" object, please review the example above. Second, value of "sshKeyIds" needs to be into double quotes because it is an string. Finally, I recommend you put all objects and string values into double quotation mark due to it is the JSON standard format, you can verify this information in jQuery.parseJSON single quote vs double quote and http://www.json.org/.

重要:在使用placeOrder方法之前,建议您先执行verifyOrder .当您准备订购时,只需在URL请求中按placeOrder更改verifyOrder.

Important: Before to use placeOrder method I recommend you to execute verifyOrder first. When, you are ready to order just change verifyOrder by placeOrder in the URL request.

我将您的请求修改如下

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
                }
            ]           
        }
    ]
} 

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

Let me know if you have any doubt or need further assistance.

这篇关于softlayer api:订购时如何订购公共二级IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆