Unable to Retrieve Item Category Information from GetConfiguration API Call in Go
The REST API call
GET https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/257/getConfiguration?objectMask=mask[itemCategory]
populates the itemCategory field in the returned Product_Package_Order_Configuration object, as seen in the following 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 } }
However, when using the Go programming language to make the same call, itemCategory remains empty despite being specified in the object mask, as demonstrated in the following code snippet:
package main import ( "fmt" "encoding/json" "github.com/softlayer/softlayer-go/session" "github.com/softlayer/softlayer-go/services" ) func main() { username := "set-me" apikey := "set-me" sess := session.New(username, apikey) sess.Debug = true service := services.GetProductPackageService(sess) mask := "itemCategory" result, err := service.Mask(mask).Id(257).GetConfiguration() if err != nil { fmt.Printf("\n Unable to retrieve config:\n - %s\n", err) return } jsonFormat, jsonErr := json.MarshalIndent(result, "", " ") if jsonErr != nil { fmt.Println(jsonErr) return } fmt.Println(string(jsonFormat)) }
The sample output shows that the itemCategory field is not populated, despite being included in the object mask:
Sample entry: { "id": 7167, "isRequired": 0, "itemCategoryId": 390, "orderStepId": 1, "packageId": 257, "sort": 0 }
Solution:
The issue arises from a discrepancy between the REST and XMLRPC endpoints. The provided code is currently configured for the XMLRPC endpoint, as indicated by the presence of the domains, user, and apiKey parameters. To use the REST endpoint, replace this section in the code:
sess := session.New(username, apikey)
with:
endpoint := "https://api.softlayer.com/rest/v3" sess := session.New(username, apikey, endpoint)
By using the REST endpoint, you can access the itemCategory information as intended.
The above is the detailed content of Why is the itemCategory field empty when using the GetConfiguration API call in Go, despite being specified in the object mask?. For more information, please follow other related articles on the PHP Chinese website!