LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

JAMA & the RESTful interface

Solved!
Go to solution

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?

0 Kudos
Message 1 of 14
(3,334 Views)

@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.  

0 Kudos
Message 2 of 14
(3,207 Views)

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:

 

Advanced Authentication (OAuth)

Basic 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”

 

Header
Authorization: Basic bXl1c2VybmFtZTpteXBhc3N3b3Jk

Curl Example
curl -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?

0 Kudos
Message 3 of 14
(3,012 Views)

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.

 

 

0 Kudos
Message 4 of 14
(2,994 Views)

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.

Rolf Kalbermatter
My Blog
Message 5 of 14
(2,989 Views)

Cool! Any idea on how to create the token?

0 Kudos
Message 6 of 14
(2,985 Views)

As I stumble through this, here is where I am at.

 

  1. in my URL, I needed the 's' in https to create a secure connection.
  2. I need the cookie file specified and the jama-csrf-token appears in the cookie file. So I am going to believe that this is being handled under the hood.

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.

0 Kudos
Message 7 of 14
(2,975 Views)

@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.

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 14
(2,970 Views)

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.

0 Kudos
Message 9 of 14
(2,966 Views)

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.

0 Kudos
Message 10 of 14
(2,960 Views)