softlayer api: How to order Public Secondary IP Ad

2019-08-16 17:41发布

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

enter image description here

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-16 17:57

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

Below is an example in JSON for REST:

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

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.

CategoryID

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

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

QuestionID

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

It should returns something like this:

{
    "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
    }
},

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

Order Virtual Guest with a Secondary Public Ip Address

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

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

    ]
}

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.

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/.

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.

I modified your request as following

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.

查看更多
登录 后发表回答