doupu1957 2018-05-08 19:44
浏览 62
已采纳

从golang调用时无法从调用GetConfiguration获取itemCategory信息

The api call

GET https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/257/getConfiguration?objectMask=mask[itemCategory]

returns an object, []datatypes.Product_Package_Order_Configuration where ItemCategory is populated. sample output:

{
"id": 7167,
"isRequired": 0,
"itemCategoryId": 390,
"orderStepId": 1,
"packageId": 257,
"sort": 0,
"itemCategory": {
"categoryCode": "trusted_platform_module",
"id": 390,
"name": "Server Security",
"quantityLimit": 1,
"sortOrder": 0
}
},

When I attempt the same call in go, itemCategory is not populated, even though I declare it in the mask. Please advise.

package main

import (
"fmt"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"encoding/json"
)

func main() {
    // SoftLayer API username and key
    username := "set-me"
    apikey   := "set-me"

    // Create a session
    sess := session.New(username, apikey)

    // Enable debug
    sess.Debug = true

    // Get SoftLayer_Account service
    service := services.GetProductPackageService(sess)

    // Object-Mask to get specific Vlan's information
    mask := "itemCategory"

    // Call to getNetworkVlans in order to retrieve vlans according to filter.
    result, err := service.Mask(mask).Id(257).GetConfiguration()
    if err != nil {
        fmt.Printf("
 Unable to retrieve config:
 - %s
", err)
        return
    }

    // Following helps to print the result in json format.
    jsonFormat, jsonErr := json.MarshalIndent(result,"","     ")
    if jsonErr != nil {
        fmt.Println(jsonErr)
        return
    }
    fmt.Println(string(jsonFormat))
}

sample output:

->>>Request:
2018/05/09 09:24:36 POST /xmlrpc/v3.1/SoftLayer_Product_Package HTTP/1.1
Host: api.softlayer.com
User-Agent: Go-http-client/1.1
Content-Length: 1055
Content-Type: text/xml
Accept-Encoding: gzip

<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>getConfiguration</methodName><params><param><value><struct><member><name>headers</name><value><struct><member><name>User-Agent</name><value><string>softlayer-go/v0.1.0-alpha (go1.9.2;amd64;darwin)</string></value></member><member><name>authenticate</name><value><struct><member><name>username</name><value><string>[[SL_USER]]</string></value></member><member><name>apiKey</name><value><string>[[SL_APIKEY]]</string></value></member></struct></value></member><member><name>SoftLayer_Product_PackageInitParameters</name><value><struct><member><name>id</name><value><int>257</int></value></member></struct></value></member><member><name>SoftLayer_Product_PackageObjectMask</name><value><struct><member><name>mask</name><value><struct><member><name>itemCategory</name><value><array><data></data></array></value></member></struct></value></member></struct></value></member></struct></value></member></struct></value></param></params></methodCall>
2018/05/09 09:24:36 


<<<-Response:
2018/05/09 09:24:36 HTTP/1.1 200 OK
Connection: close
Transfer-Encoding: chunked
Cache-Control: private
Content-Type: text/xml
Date: Wed, 09 May 2018 14:24:36 GMT
Server: Apache
Softlayer-Total-Items: 39
Strict-Transport-Security: max-age=31536000
Vary: Accept-Encoding
X-Frame-Options: SAMEORIGIN

Then a string of html with the same data as below is returned Sample entry:

{
          "id": 7167,
          "isRequired": 0,
          "itemCategoryId": 390,
          "orderStepId": 1,
          "packageId": 257,
          "sort": 0
     },
  • 写回答

1条回答 默认 最新

  • 普通网友 2018-05-09 15:09
    关注

    The default endpoint is REST but in your environment you are using xmlrpc, which is probably due to the existence of the ~ / .softlayer file and in this it is configured as an XMLRPC enpoint.

    For more information you can see the following documentation: https://github.com/softlayer/softlayer-go

    This issue happens for the XMLRPC enpoint and you can report it in the go GitHub. https://github.com/softlayer/softlayer-go/issues/

    Try in your code with the REST endpoint, like this example:

    endpoint := "https://api.softlayer.com/rest/v3"
    
    // Create a session
    sess := session.New(username, apikey, endpoint)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来