I am trying to use the DT API to programmatically retrieve
information on monitored hosts. My code is implemented in Java and it works
correctly until I try to add a parameter to return only hosts that have a
specific tag. I.e., I make a call referencing a URL like:
env ID>/api/v1/entity/infrastructure/hosts?Api-Token=<the token>&tag=APP=MyAppTag(ABC)
This fails when it is called via the java code, but works if I
copy/paste the URL into a browser. If, however, I remove the tag reference (as
below) it works when called by my java program.
env ID>/api/v1/entity/infrastructure/hosts?Api-Token=<the token>
Has anyone encountered this type of problem before? Since the URL
works in a browser and works if I remove the tag reference I wonder if the
& character, or perhaps other characters that are in my tag like the ‘(‘ or
‘)’ character are somehow causing the code to fail. I initially assumed, of course, that there was something wrong with how my code was constructing the URL, but as mentioned above the URL (as shown when I run the program in debug mode) looks correct + works when I copy/paste it into a browser.
My code looks like the
following, and the failure occurs when creating the input stream reader.
myUrl = new URL(httpsURL);
conn = (HttpsURLConnection)myUrl.openConnection();
is = conn.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
APICallResults = br.readLine();
The IOException error I receive states “at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown
Solved! Go to Solution.
I think your code is having issues while parsing the URL, try to do the same query but instead of using an complex tag like "tag=APP=MyAppTag(ABC) – ENV=TEST" create a manual one "test" and try with "tag=test".
This should work and then move forward with the rest of special characters you are using on your tags