Forum Discussion
Ok, so I downloaded a pipeline I found on your site and it works, but I’m confused as to why mine won’t work using the following:
“https://elastic.snaplogic.com/api/1/rest/public/runtime/” + _org + “?last_hours=” + _last_hours + “?state=” + _state
The one I found (below) is much more complicated and I don’t want to just use it without understanding why mine doesn’t work. So obviously, I have rights to see “everything”.
‘https://elastic.snaplogic.com/api/1/rest/public/runtime/’ + pipe.plexPath.split(‘/’)[1] + ‘?level=summary’ + (_state == null || _state ==“” ? ‘’ : ‘&state=’+ _state) + (_hours == null || _hours ==“” ? ‘’ : ‘&last_hours=’+ _hours) + (_batchsize == null || _batchsize ==“” ? ‘’ : ‘&limit=’+ _batchsize)
My ‘_org’ is preset to our org, but I’ll probably change it to the more generic one.
I do realize a lot of that has nothing to do with the data I want to see, but load balancing for paging.
There was a high level explanation of the api call directly above on the article I found, but not why all the gymnastics with the state parameter and the hours parameter. Also, the ‘level’ parm is not listed on the page you referred me to.
Breaking this command down into the individual elements for explanation:
First is just the path of the API call:
‘https://elastic.snaplogic.com/api/1/rest/public/runtime/’
Next is a dynamic way of specifying the org that the pipeline executing the REST GET - pipe.plexPath is a built-in property that gives the full path of the pipeline being executed, then we break that string down into an array of strings using the String.split() method, and finally grab only the array element at index 1.
+ pipe.plexPath.split(‘/’)[1]
Finally, we are using some pipeline parameters to build out the remaining query elements in the URL. If you are not familiar with ternary operators, please take a look at the “Special Operators” section of the Expression Operators documentation.
+ ‘?level=summary’ + (_state == null || _state ==“” ? ‘’ : ‘&state=’+ _state)
+ (_hours == null || _hours ==“” ? ‘’ : ‘&last_hours=’+ _hours)
+ (_batchsize == null || _batchsize ==“” ? ‘’ : ‘&limit=’+ _batchsize)`
I hope this helps!