08-06-2020 09:18 AM
I would like to download data from JAMA which has a RESTful interface. I found examples in other programming languages, https://github.com/jamasoftware-ps/REST-References but I struggle to take these examples to something that works in LabVIEW. Anyone have any suggestions/example of how to implement an example to get data out of JAMA?
Solved! Go to Solution.
09-15-2020 04:40 AM
@JoeLV1992 wrote:
I would like to download data from JAMA which has a RESTful interface. I found examples in other programming languages, https://github.com/jamasoftware-ps/REST-References but I struggle to take these examples to something that works in LabVIEW. Anyone have any suggestions/example of how to implement an example to get data out of JAMA?
I don't know anything about JAMA. I do know RESTful requests are simply HTTP get\set requests. So you can use the VIs (Data Communication>Protocols>HTTP Client) and examples for HTTP...
A REST\RESTful request is simply a HTTP GET to the right URL. You can even type the URL in a browser, and get the result... A PUT set data, although often the server also accepts GET with the PUT data as well.
The send data are specific to JAMA. They can be plain text, binary, XML, anything really.
08-23-2021 10:57 AM - edited 08-23-2021 11:04 AM
OK, I had to shelve this project for a little bit, and I am back to it.
I think I am getting stuck at authentication:
Most rest clients have an easy interface for basic authentication. You must provide your username and password in the header of the request following the RFC 2617 standard
Note: This type of authentication will not work in a SAML/SSO environment.
Examples for username: “myusername” and password: “mypassword”
HeaderAuthorization: Basic bXl1c2VybmFtZTpteXBhc3N3b3Jk
Curl Examplecurl -u myusername:mypassword http://basepath/rest/v1/projects
I am curious to know if the Open Handle is performing this function because I do not see authorization as one of the items to select from the add header function?
08-24-2021 07:21 AM
Some more clues.
JAMA has a utility called, "Swagger". It provides a developer interface to the REST API. There is a very simple GET procedure named, "/projects" that will provide a list of projects on a server.
where the URL is (replacing the actual server name with <server name>:
https://<server_name>/contour/rest/latest/projects
and the GET statement/URL is a CURL command as follows with the server name and token removed
curl -X GET "https://<server_name/contour/rest/latest/projects" -H "accept: application/json" -H "jama-csrf-token: tokenremovedforprivacy"
where -H are GET statement headers.
So here is where I am limited with the LabVIEW toolkit:
1) I cannot see what the actual URL with headers are that are sent to the server
2) The headers I can see are the ones that I set. So I can set the accept header, but I cannot set the jama-csrf-token as is it is not a standard header
3) The authentication function in the pallet is locked so I cannot see what it is doing.
08-24-2021 07:42 AM
The HTTP Client library has a function Add Header.vi to add extra header fields. The header parameter is a drop down list with standard headers but it uses the LabVIEW Combo Box control which accepts ANY string you want to add, so just enter the header field name your service expects.
08-24-2021 08:33 AM
Cool! Any idea on how to create the token?
08-24-2021 09:53 AM
As I stumble through this, here is where I am at.
So now I get a lot more headers from the server, and with the reply:
{"meta":{"status":"Unauthorized","timestamp":"2021-08-24T14:37:47.773+0000","message":""}}
So, I think, this must be a server or security thing to get setup. Onto bugging them.
08-24-2021 10:22 AM
@JoeLV1992 wrote:
Cool! Any idea on how to create the token?
That is usually REST service specific. For many services you register at the service and receive a service token of some form. Possibly it is stored automatically in a cookie for the current session when you work from within a browser and if you stay in that browser session it may automatically reuse it but for other services you often need to register for a specific API token that identifies you or your application to the service provider. How that needs to be done varies per service and should be documented by the REST API documentation for that service.
08-24-2021 10:40 AM
I also found this in the cookie file. JAMA may not support Netscape?
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
08-24-2021 11:09 AM - edited 08-24-2021 11:11 AM
There are tokens written to the cookie file. I read the API documentation, and the examples are in JAVA (which is not LabVIEW). You use a single command with some command-line switches, and it just works. I am not successful in the translation, or there is some minute detail in an example that will free the bits from the security hassle.