Celso Fernandes
Celso Fernandes

Reputation: 83

SoftLayer Account not considering the Object Mask

Problem: I'm trying to hit the API and use an Object Mask for SoftLayer_Account#getVirtualGuests, but it seems to be ignored.

What I've tried:

Calling SoftLayer_Virtual_Guest.getObject with header

<SoftLayer_Virtual_GuestObjectMask>
  <mask>
    <datacenter xsi:nil="true" />
    <bandwidthAllotmentDetail><allocation xsi:nil="true" /></bandwidthAllotmentDetail>
  </mask>
</SoftLayer_Virtual_GuestObjectMask>

Works perfectly, but when I call SoftLayer_Account.getVirtualGuests with header

<SoftLayer_AccountObjectMask>
  <mask>
    <datacenter xsi:nil="true" />
    <bandwidthAllotmentDetail><allocation xsi:nil="true" /></bandwidthAllotmentDetail>
  </mask>
</SoftLayer_AccountObjectMask>

it doesn't work, as I've seen on https://sldn.softlayer.com/article/object-masks article, when calling SoftLayer_Account::getHardware you need to set the root property for a particular type, but according to the example I can't figure out how to call using SOAP.

If an example could be provided on how to use Object Mask and Object Filter for SoftLayer_Account.getVirtualGuests I can handle on my side.

Thank you

Upvotes: 0

Views: 272

Answers (2)

mcruz
mcruz

Reputation: 1532

Please, try the following example using SOAP request:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v3="http://api.service.softlayer.com/soap/v3/">
  <soapenv:Header>
    <authenticate xsi:type="v3:authenticate">
      <username xsi:type="xsd:string">?</username>
      <apiKey xsi:type="xsd:string">?</apiKey>
    </authenticate>
    <v3:SoftLayer_ObjectMask xsi:type="v3:SoftLayer_ObjectMask">
      <mask xsi:type="xsd:string">mask[id,datacenter,bandwidthAllotmentDetail]</mask>
    </v3:SoftLayer_ObjectMask>
    <SoftLayer_AccountObjectFilter xsi:type="v3:SoftLayer_AccountObjectFilter"/>
    <SoftLayer_AccountObjectMask xsi:type="v3:SoftLayer_AccountObjectMask">
      <mask xsi:type="v3:SoftLayer_Account"/>
    </SoftLayer_AccountObjectMask>
  </soapenv:Header>
  <soapenv:Body>
    <v3:getVirtualGuests soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  </soapenv:Body>
</soapenv:Envelope>

If you want to combine object Masks and object Filters, please see:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v3="http://api.service.softlayer.com/soap/v3/">
  <soapenv:Header>
    <authenticate xsi:type="v3:authenticate">
      <username xsi:type="xsd:string">?</username>
      <apiKey xsi:type="xsd:string">?</apiKey>
    </authenticate>
    <v3:SoftLayer_ObjectMask xsi:type="v3:SoftLayer_ObjectMask">
      <mask xsi:type="xsd:string">filteredMask[id,datacenter,bandwidthAllotmentDetail]</mask>
    </v3:SoftLayer_ObjectMask>
    <v3:SoftLayer_AccountObjectFilter xsi:type="v3:SoftLayer_AccountObjectFilter">
      <virtualGuests>
        <datacenter>
          <name>
            <operation>dal06</operation>
          </name>
        </datacenter>
      </virtualGuests>
    </v3:SoftLayer_AccountObjectFilter>
    <SoftLayer_AccountObjectMask xsi:type="v3:SoftLayer_AccountObjectMask">
      <mask xsi:type="v3:SoftLayer_Account"/>    
    </SoftLayer_AccountObjectMask>
  </soapenv:Header>
  <soapenv:Body>
    <v3:getVirtualGuests soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  </soapenv:Body>
</soapenv:Envelope>

Upvotes: 1

greyhoundforty
greyhoundforty

Reputation: 239

I am not seeing an issue using Object Masks with the getVirtualGuests call

curl -s -g --user "$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY" "https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests.json?objectMask=mask[domain,bandwidthAllotmentDetail]" | python -m json.tool
[
    {
        "bandwidthAllotmentDetail": {
            "allocationId": 5318597,
            "bandwidthAllotmentId": 138442,
            "effectiveDate": "2016-02-12T11:45:38-06:00",
            "endEffectiveDate": null,
            "id": 5479443,
            "serviceProviderId": 1
        },
        "domain": "tinylab.info"
    },
    {
        "bandwidthAllotmentDetail": {
            "allocationId": 5569801,
            "bandwidthAllotmentId": 138442,
            "effectiveDate": "2016-03-22T10:17:46-06:00",
            "endEffectiveDate": null,
            "id": 5736289,
            "serviceProviderId": 1
        },
        "domain": "tinylayer.net"
    },
    {
        "bandwidthAllotmentDetail": {
            "allocationId": 5468679,
            "bandwidthAllotmentId": 138442,
            "effectiveDate": "2016-03-04T00:00:00-06:00",
            "endEffectiveDate": null,
            "id": 5633115,
            "serviceProviderId": 1
        },
        "domain": "tinylab.info"
    },
    {
        "bandwidthAllotmentDetail": {
            "allocationId": 5600063,
            "bandwidthAllotmentId": 138442,
            "effectiveDate": "2016-03-28T08:32:41-06:00",
            "endEffectiveDate": null,
            "id": 5767743,
            "serviceProviderId": 1
        },
        "domain": "tinylab.info"
    }
]

This is returning a json list of all the Virtual Guests on my account with the bandwidthAllotmentDetail part of the API response.

Upvotes: 0

Related Questions