Reply

_return_fields is ignored in curl request

Authority
Posts: 31
8028     1

Hello,

I'm currently deploying Infoblox.  We're only using it as IPAM, not DNS or DHCP.  I'm able to do a lot of what I need via curl requests to the API, but for some reason it seems to be ignoring the _return_fields.  If I don't add _return_fields, I get this back:

[

{
"_ref": "network/ZG5zLm5ldHdvcmskNjguMTY5LjE3Mi4xNTIvMzIvMA:x.x.x.x/32/default",
"network": "x.x.x.x/32",
"network_view": "default"
}

]

 

If I add network and comment to the return fields, I still get the network, but not the network_view (which it appears to add by default, when _return_fields isn't specified), and I don't get comment:

{

[

curl -k1 -u userSmiley Tonguew -X GET https://192.168.x.x/wapi/v2.0/network -d *Building='DAIOLT1' -d *Group='Static' -d _max_results=1 -d _return_fields="network,comment"

[
{
"_ref": "network/ZG5zLm5ldHdvcmskNjguMTY5LjE3Mi4xNTIvMzIvMA:x.x.x.x/32/default",
"network": "x.x.x.x/32"
}

]

 

I've tried many combinations of fields, and it ignores them all in _return_fields.  I've also tried with and without quotes, but it still doesn't change.  Realistically, there's a whole list of things that I'd like to return (some of which are EAs), but I'm keeping it simple by just requesting two!  Hopefully someone will see something I'm overlooking!

 

Any help is appreciated!

 

Blair

Re: _return_fields is ignored in curl request

Adviser
Posts: 135
8028     1

There may be multiple things going on here. If you do not use _return_fields then you will get a standard set of fields returned. When querying for network objects the fields returned by default will be network, network_view, and comment. (These are in addition to the _ref object reference, which is always returned.) However... if a particular network does not have a comment value specified for it then the comment field will not be returned for that object. For example, on my demo grid the curl command

 

curl --tlsv1 --insecure --user 'admin:infoblox' 'htts://gm.example.com/wapi/v2.2/network'

 

will return the following networks (among other) and their associated fields:

 

[
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTkyLjE2OC4yMDEuMC8yNi8z:192.168.201.0/26/test", 
        "network": "192.168.201.0/26", 
        "network_view": "test"
    }, 
    ...
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMC4wLjAvMjQvMA:10.0.0.0/24/default", 
        "comment": "Demo lab network", 
        "network": "10.0.0.0/24", 
        "network_view": "default"
    }
]

 

Here the first network does not have a value for the comment field set, and hence the comment field is not part of the result set for that network.

 

When you use the _return_fields parameter then the set of fields returned is the set specified, and no other fields (except for _ref). Again, if the comment field has no value for a network object then it will not be returned:

 

curl --tlsv1 --insecure --user 'admin:infoblox' 'htts://gm.example.com/wapi/v2.2/network?_return_fields=network,comment'

 

[
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTkyLjE2OC4yMDEuMC8yNi8z:192.168.201.0/26/test", 
        "network": "192.168.201.0/26"
    }, 
    ...
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMC4wLjAvMjQvMA:10.0.0.0/24/default", 
        "comment": "Demo lab network", 
        "network": "10.0.0.0/24"
    }
]

 

Finally, if you want to return the standard set of fields (at least, those of the standard fields that are defined) plus additional fields then you use the _return_fields+ parameter; depending on how you make the WAPI call you may have to explicitly URL-encode "_return_fields+" as "_return_fields%2b", as in the following curl command:

 

curl --tlsv1 --insecure --user 'admin:infoblox' 'htts://gm.example.com/wapi/v2.2/network?_return_fields%2b=members'

 

Here there are no grid members assigned to the network 10.0.0.0/26 in the network view "test", and the value of the members field is an empty list (instead of being omitted, as with the comment field).

 

[
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTkyLjE2OC4yMDEuMC8yNi8z:192.168.201.0/26/test", 
        "members": [], 
        "network": "192.168.201.0/26", 
        "network_view": "test"
    }, 
    ...
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMC4wLjAvMjQvMA:10.0.0.0/24/default", 
        "comment": "Demo lab network", 
        "members": [
            {
                "_struct": "dhcpmember", 
                "ipv4addr": "10.0.0.122", 
                "ipv6addr": null, 
                "name": "gm2.example.com"
            }, 
            {
                "_struct": "dhcpmember", 
                "ipv4addr": "10.0.0.121", 
                "ipv6addr": null, 
                "name": "gm1.example.com"
            }
        ], 
        "network": "10.0.0.0/24", 
        "network_view": "default"
    }
]

 

If you believe that the _return_fields or _return_fields+ parameters are not resulting in the correct set of fields being returned for your own WAPI calls, please post an example curl command and a sample of the output that you think is incorrect.

Re: _return_fields is ignored in curl request

Authority
Posts: 31
8028     1

Thank you, FHecker, that helps a lot.  I didn't realize that it was just leaving out the null field.

 

This may turn into another question, and the more I think about it, I can live without it and just trust that the results are correct...but how would I return EAs? For example, I've got one called Group.  I've successfully filtered on *Group, but that doesn't work in _return_fields.

 

Here's an example of trying 'Group', '*Group', and 'EA-Group' (since that's what it was called in the CSV, I thought I'd give it a try)

 

Blair@blairs-mbp:/Applications/ApacheDirectoryStudio.app/configuration$ curl -k1 -u adminSmiley Tonguew -X GET https://x.x.x.x/wapi/v2.0/network -d *Building='DAIOLT1' -d *Group='Static' -d _max_results=3 -d _return_fields=Group
{ "Error": "AdmConProtoError: Unknown argument/field: 'Group'",
"code": "Client.Ibap.Proto",
"text": "Unknown argument/field: 'Group'"
}

Blair@blairs-mbp:/Applications/ApacheDirectoryStudio.app/configuration$ curl -k1 -u adminSmiley Tonguew -X GET https://x.x.x.x/wapi/v2.0/network -d *Building='DAIOLT1' -d *Group='Static' -d _max_results=3 -d _return_fields=*Group
{ "Error": "AdmConProtoError: Unknown argument/field: '*Group'",
"code": "Client.Ibap.Proto",
"text": "Unknown argument/field: '*Group'"
}

 

Thanks!

Blair

Blair@blairs-mbp:/Applications/ApacheDirectoryStudio.app/configuration$ curl -k1 -u adminSmiley Tonguew -X GET https://x.x.x.x/wapi/v2.0/network -d *Building='DAIOLT1' -d *Group='Static' -d _max_results=3 -d _return_fields=EA-Group
{ "Error": "AdmConProtoError: Unknown argument/field: 'EA-Group'",
"code": "Client.Ibap.Proto",
"text": "Unknown argument/field: 'EA-Group'"

Re: _return_fields is ignored in curl request

Adviser
Posts: 135
8028     1

The issue here is that even though there's a special syntax to search for objects with a particular extensible attribute value as part of a WAPI GET request, the actual extensible attribute itself is not a field like the other fields in the object. Instead extensible attributes are defined as subfields of the field extattrs.

 

For example, in my lab grid I've defined an extensible attribute Department and defined values of that EA for some of my networks. To see what values of the Department EA my networks have, I would use the _return_fields or _return_fields+ parameter with the field extattrs:

 

curl --tlsv1 --insecure --user 'admin:infoblox' 'htts://gm.example.com/wapi/v2.2/network?_return_fields%2b=extattrs'

 

This would give me results like the following; note that one network has the extensible attribute State defined for it in addition to Department:

 

[
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTkyLjE2OC4yMDEuMC8yNi8z:192.168.201.0/26/test", 
        "extattrs": {
            "Department": {
                "value": "Sales"
            }
        }, 
        "network": "192.168.201.0/26", 
        "network_view": "test"
    },
    ...
        {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMC4wLjAvMjQvMA:10.0.0.0/24/default", 
        "comment": "Demo lab network", 
        "extattrs": {
            "Department": {
                "value": "Engineering"
            }, 
            "State": {
                "value": "MD"
            }
        }, 
        "network": "10.0.0.0/24", 
        "network_view": "default"
    }
]

 

But if I wanted to return only those networks where the value of the Department field were equal to "Engineering" then I would use the following syntax:

 

curl --tlsv1 --insecure --user 'admin:infoblox' 'htts://gm.example.com/wapi/v2.2/network?*Department=Engineering'

 

If for some reason I wanted to see the actual value of the EA, or if I wanted to see the value of other EAs for the same object(s), then I would use _return_fields or _return_fields+ to get the complete contents of the extattrs field, as in the first example above:

 

curl --tlsv1 --insecure --user 'admin:infoblox' 'htts://gm.example.com/wapi/v2.2/network?*Department=Engineering&_return_fields%2b=extattrs'

 

The results would be similar to those shown above for the first example, except that the results would include only the second network and not the first.

 

Frank

Re: _return_fields is ignored in curl request

Authority
Posts: 31
8029     1

Perfect!  That's what I needed.  Thank you!

Showing results for 
Search instead for 
Did you mean: 

Recommended for You