Why is the itemCategory field empty when using the GetConfiguration API call in Go, despite being specified in the object mask?

DDD
Release: 2024-11-16 02:38:03
Original
363 people have browsed it

Why is the itemCategory field empty when using the GetConfiguration API call in Go, despite being specified in the object mask?

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]
Copy after login

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
}
}
Copy after login

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))
}
Copy after login

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
}
Copy after login

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)
Copy after login

with:

endpoint := "https://api.softlayer.com/rest/v3"
sess := session.New(username, apikey, endpoint)
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template