0

I am in trouble with using ObjectFilter on softlayer API.

I'm testing Softlayer API to retrieve host IQN, username and password of block storage.

I have tried with the command below, but objectFilter is not working at all.

curl -g 'https://username:api_key@api.softlayer.com/rest/v3/SoftLayer_Network_Storage/storage_ID/getObject?objectMask=mask[id,username,allowedIpAddresses[ipAddress,allowedHost[name,credential[username,password]]]]'

It returns 3 network objects including IQN, username , password as I expected.

So I want to make filter by "ip address" by below api command but not worked. (It seems objectFilter is ignoring)

curl -g 'https://username:api_key@api.softlayer.com/rest/v3/SoftLayer_Network_Storage/storage_ID/getObject?objectMask=mask[id,username,allowedIpAddresses[ipAddress,allowedHost[name,credential[username,password]]]]&objectFilter={"object":{"allowedIpAddresses":{"ipAddress":{"operation":"1.2.3.4"}}}}'

Is this something wrong with my API usage?

Top Sekret
  • 748
  • 5
  • 21

1 Answers1

0

Actually the filter is working but you won't notice as there is a slight difference between object mask and filters, remember that Object filters can be used to limit the results returned by the API, they differ from object masks in that they determine what Data Type objects are returned (in this particular case the whole SoftLayer_Network_Storage single object and the relational properties you can see returned by using your object mask, for example [allowedIpAddresses] array), while Object Masks define what properties to retrieve from the returned objects.

For example, another way to retrieve and demonstrate how filters work, you may try the following request:

curl -g "https://[username]:[apiKey]@api.softlayer.com/rest/v3.1/SoftLayer_Account/getNetworkStorage?objectMask=mask[id,username,allowedIpAddresses[ipAddress,allowedHost[name,credential[username,password]]]]&objectFilter=%7B%22networkStorage%22%3A%7B%22allowedIpAddresses%22%3A%7B%22ipAddress%22%3A%7B%22operation%22%3A%22[ipAddress]%22%7D%7D%7D%7D"

This method retrieves an Array of all the account's associated storage volumes, including Lockbox, NAS, EVault, and iSCSI volumes (among them your block storage on it).

You may use the request without the object filter and verify all the objects returned by just using your object Mask, and then use the complete request with the object filter verifying that it narrowed the objects returned to the single object of your block storage by using the ipAddress you define on it.

For more information please see below:

https://sldn.softlayer.com/blog/bpotter/going-further-softlayer-api-python-client-part-1

https://sldn.softlayer.com/article/object-filters

https://sldn.softlayer.com/article/object-masks

Fernando Iquiza
  • 531
  • 3
  • 7
  • As you guided , I tried it and saw the differences, but I really don't know how to retrieve single object because I'm really new to REST API. Can you please help me with more complete API usage ? I want to retrieve single object that filtered by IP address. – HongSeog Kim Jul 13 '17 at 03:50
  • By using SoftLayer_Network_Storage::getObject you are already returning only a single object of the same datatype where the filter is working on, but with SoftLayer_Account::getNetworkStorage you return an array of objects, remember that filters work over the returned value so if you use a filter over a returned object with specific properties like allowedIpAddresses then you won't notest the filter as the mask is returning the **whole** allowedIpAddresses property no matter what. I truly recommend you to read the SLDN documentation I provided previously. – Fernando Iquiza Jul 13 '17 at 19:44
  • Here is another forum related to SLDN Api object filters: https://stackoverflow.com/questions/41186972/how-to-use-object-filter-with-softlayer-rest-api/41189063#41189063 – Fernando Iquiza Jul 13 '17 at 19:57