How to negotiate a Plain text response from Mango 3.6 Rest API
-
Hi Phil,
Thanks so much for offering a solution!! I believe I understand what I need to do.
However, When I try to compile the class in Windows 7 using the following command:C:\Program Files\Java\jdk1.8.0_144\bin>javac -cp C:\Mango356\lib\*; C:\Mango356\ web\modules\mangoApi\lib\CustomizedRestController.java
I Recieve the following error:
C:\Mango356\web\modules\mangoApi\lib\CustomizedRestController.java:11: error: pa ckage com.infiniteautomation.mango.rest.v2.exception does not exist import com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException; ^ 1 error
I had copied the CustomizedRestController.java to my "C:\Mango356\web\modules\mangoApi\lib" directory,
and also created the folders "com\infiniteautomation\mango\rest\v2" within the "C:\Mango356\web\modules\mangoApi\lib" directory as well. I'm sure I'm missing something. I do not do much java compiling.Thanks again for the help!
-
The javac command doesn't look like mine. My
-cp
argument has no space in it, and has the Mango API lib directory as the second classpath location (they are semicolon delimited), and I did not provide an absolute path to the CustomizedRestController.java since I was in the same directory (but the issue with the class not found is to do with no API in the classpath argument). -
Thanks Phil,
I was able to get it to compile by switching to the
C:\Mango356\web\modules\mangoApi\lib
directory, and then use the following command:javac -cp C:\Mango356\lib\*;C:\Mango356\web\modules\mangoApi\lib\* CustomizedRestController.java
I then copied the
CustomizedRestController.class
file that was created, to theC:\Mango356\web\modules\mangoApi\lib\com\infiniteautomation\mango\rest\v2
directory.I then ran
jar uf mango-api-3.6.0.jar com/infiniteautomation/mango/rest/v2/CustomizedRestController.class
and did not recieve any errors at all. I then restarted Mango, and went into swagger, but fail to see any URL path t o access this custom endpoint. I tried accessing:http://localhost:8080/rest/v2/custom/latest-value-only/DP_059c7915-c0e7-48dc-b9e3-28ca8b92da01?fields=VALUE&limit=1&useCache=NONE
but got a "page not found" error. Again, thanks for all the help! -
Hi Phil,
Nevermind! Apparently the command:
jar uf mango-api-3.6.0.jar com/infiniteautomation/mango/rest/v2/CustomizedRestController.class
did not actually take the first time. I think Mango was running by mistake, when I ran it the first time.
It's actually all working now, and I see the plain text data that I need for my application!!
Brilliant as always Phil!!
Thanks again!!
-
:D Glad to hear it, I was trying to figure out what could have gone awry as I had tested it before posting!
Happy hacking!
-
On a side note to this application, When I use this Rest URL from my third-party app on the same network, Will I recieve any authentication challenges "Auth Tokens" before Mango will display the data? Right now, It works fine in my localhost browser, but I'm not sure about a remote application.
-
@raylatbasix all endpoints located below
/rest
are restricted to authenticated users. For a 3rd party app I would suggest token authentication which is quite easy to use from the client side by including the token in the Authorization header as shown on this page:https://help.infiniteautomation.com/mango-rest-api-authentication?rq=token
Ensure you use https to protect the token.
-
Hi Terry,
Sorry for being a newbie, but How would I pass this JWT Auth token within a request URL to the Rest API? -
The header is Authorization, the value is Token <token value> like
Authorization: Bearer <token value>
and you can generate auth tokens for users on the users page. -
Whoops, wrote that wrong, don't trust the email notification text!
Authorization: Bearer <token value>
-
Hi Phil,
Yes, I saw that, and forgive my ignorance, I can generate user tokens. My problem is that I can only modify the URL on my third party app. I am not understanding how to pass this authorization token from within my request URL.
Sorry for the crazy question :)
EDIT: In other words, what is my URL's format for reqesting data? ie:
http://localhost:8080/rest/v2/custom/latest-value-only/DP_e64bb726-ddd4-4065-8972-21c9441af408?access_token=<auth token here>??????
-
Good Morning Phil,
You can cancel this request, I was able to solve my Authorization Request Header issue.
Thanks again for all the help!!