DX NetOps Manager

Tech Tip: Calling OpenAPI/odata query from curl 

05-12-2017 04:29 AM

The easiest way to call a OpenAPI/odata query from a shell script is via curl command. However,  some aspects need to be considered to make it work.

 

Syntax 
curl -u user:password -G -X GET -d 'parameters' 'URL'

  • URL is the portion before the ? in the original odata query, parameters is the portion after
  • both URL and parameters need to be enclosed in single quotes
  • parameters string has substitution characters such as %20 for blank. Simply copy the odata query to Chrome, it will perform the conversion. Then copy the string from the Chrome line.
    (you will need to verify your odata query anyway) 

 

Example:

curl -u myuser:mypassword -G -X GET -d '$apply=groupby(ID,%20aggregate(portmfs(im_BitsIn%20with%20percentile95%20as%20im_BitsIn),portmfs(im_BitsOut%20with%20percentile95%20as%20im_BitsOut)))&starttime=1490594251&endtime=1493186251&resolution=RATE&$select=ID,Name&$filter=((substringof(%27CA%27,Name)%20eq%20true))&$format=text/csv' 'http://DA-HOST:8581/odata/api/groups'

Statistics
0 Favorited
4 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

08-03-2017 10:26 AM

We have developed the following OpenAPI/Odata query by the GUI, export some IPSLA ICMP variables based on a MTF file for the last 24 hours. We increased the top, as not all was listed;

 

http://DA:8581/odata/api/icmpmfs?starttime=1501655014&endtime=1501741414&resolution=HOUR&$format=text/csv&$top=3600&$ski… 

 

To use the OdataURL this result in the following  curl query;

 

curl  --trace-time -i -b cookies.txt -c cookies.txt -u myuser:mypassword -G -X GET -d 'starttime=1501655014&endtime=1501741414&resolution=HOUR&$format=text/csv&$top=3600&$skip=0&top=100&$expand=device,component&$select=device/Name,component/DisplayName,Timestamp,min_im_AvgResponseTime,max_im_AvgResponseTime,im_AvgResponseTime,im_Attempts,im_SuccessfulAttempts&$filter=((substringof(tolower(%27cip%27),%20tolower(device/Name))%20eq%20true))' 'http://DA:8581/odata/api/icmpmfs' -o IPSLA-03-08-2017_1430.csv

Related Entries and Links

No Related Resource entered.