Reply

Bulk retrieval of objects by objref

Member
Posts: 2
1512     0

Is is possible to retrieve multiple objects by reference in a single WAPI call?  If I have an outside script that is storing references to networks by their _ref, I'd like to be able to grab all the objects in a single HTTPS GET to avoid additional overhead.

Re: Bulk retrieval of objects by objref

Adviser
Posts: 101
1512     0

I think it is not possible. As GET does not support body data. So the _ref can only be submitted as URL parameter.

Re: Bulk retrieval of objects by objref

Member
Posts: 2
1512     0

Elastic solves this issue by creating a new endpoint, "_bulk", that accepts POST requests

 

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html

 

Perhaps a future version of the WAPI could support bulk endpoints, either top-level:

 

POST wapi/v/_bulk:

[

   { "network": obj1ref },

   { "network": obj2ref }

]

 

or at the resource level:

 

POST wapi/v/network/_bulk:

[ obj1ref, obj2ref ]

 

?

 

Re: Bulk retrieval of objects by objref

Community Manager
Community Manager
Posts: 248
1512     0

use the '/request' object. This will let you bundle multiple API calls into a single payload.

 

the "odd" oart about this is that you use POST to use /request, even if you're making a GET request.

E.g:

 

  POST /wapi/v2.1/request
  Content-Type: application/json

     [{
       ’method’: ’GET’,
       ’object’: ’record:host’,
       'args': {
          '_return_fields+': 'extattrs,comment'
       }
       ’data’: {
          ’name’: ’test.somewhere.com’,
       },
     },
     {
       ’method’: ’GET’,
       ’object’: ’record:host’,
       'args': {
          '_return_fields+': 'extattrs,comment'
       }
       ’data’: {
          ’name’: ’test.elsewhere.org’,
       },    
     }]
             

Re: Bulk retrieval of objects by objref

Community Manager
Community Manager
Posts: 248
1512     0

oh, and in general GETting things by the _ref is not recommended as the _ref can change over time,

so it isn't recommended to stash this in a cache.

 

only use _ref when you want to modify an object.

 

search or get it by other search params, then modify within a short time window.

Re: Bulk retrieval of objects by objref

Member
Posts: 1
1512     0

I have an additional question for this post. If I want to search using regex for a pattern in the name... something like this:

 

[{
       ’method’: ’GET’,
       ’object’: ’record:a’,
       'args': {
          '_return_fields+': 'extattrs,comment'
       }
       ’data’: {
          ’name’: ’~=dev-test-url’,
       },
     },
     {
       ’method’: ’GET’,
       ’object’: ’record:aaaa’,
       'args': {
          '_return_fields+': 'extattrs,comment'
       }
       ’data’: {
          ’name’: ’~=sit-test-url’,
       },    
     }]

 

Is something like this possible? So far I have been unable to get this to work. Right now i am just making multiple calls and using a straight get and adding the regex comparison to the url. Would love to be able to do multiple GETs with this.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You