#915 Integration through REST API in JAVA

GAURAV SAHU Fri 7 May

Hi ,

I am new to Haystack platform , My query is : how to Integrate to Haystack Connection through using "REST API" . Please provide me the details/Example, so i can understand & use this platform.

Thanks & Regards Gaurav Sahu

Chris Breederveld Fri 7 May

Hi Gaurav,

You may want to look into the haystack-java library, and take a look at the detailed documentation

GAURAV SAHU Sat 8 May

Hi Chris Breederveld,

I have gone through the detail documentation but one of the link of Rest API page (https://project-haystack.org/doc/Rest) is not getting open. It gives 404 not Found error.

Please Guide me regarding the same.

Thanks & Regards Gaurav Sahu

Chris Breederveld Sat 8 May

Hi Gaurav,

I think that link should now point to this location because things have moved around a bit with the new docs setup.

GAURAV SAHU Mon 14 Jun

Hi Chris Breederveld,

I am new to this "Haystack" integration ,i have read and also gone through the docs, details & Example of Skyfoundry "https://github.com/skyfoundry/haystack-java" , i am phasing some complication to understand and about how to connect & Use the Haystack Tagging/features to the project. I need your help to understand that how could i use it and can you please provide me some demo videos in Java platform through REST API , So i can able to understand the structure that how it is Connecting , working and how can apply tagging to the projects.

Thanks & Regards Gaurav Sahu

Chris Breederveld Mon 14 Jun

HI Gaurav,

It is a bit hard for me to gauge your level of knowledge and where you need help exactly, but I'll try to give you some general pointers and then perhaps you can give me a bit more detail what topics you are exactly struggling with. Also I would like to know which Haystack server you are working with, this might also help with providing more specific resources.

Haystack ontology

To get some overall insight about the tagging mechanism in Haystack I can recommend this video which explains the current v4 standard (under review at the time of this video): https://www.youtube.com/watch?v=5kZZW1HCMwA

Haystack API authentication

It depends a bit what system you are connecting to, but most implementations use the SCRAM authentication method, all described in this documentation. In the Java library you can set up such a connection using this code:

HClient client = HClient.open("http://localhost/api/demo", "user", "pass");
client.about(); // <- gets some basic info, useful to test your connection.

Haystack operations

The Java client has functions like pointWrite to write records and hisRead to read historic information. You can use filters like point and equipRef->elec in function onReadAll to get a list of filtered items.

HGrid grid = client.onReadAll("point and equipRef->elec");
for (int i = 0; i < grid.numRows(); i++) {
  HRow row = grid.row(i);
  ...
}

GAURAV SAHU Tue 15 Jun

HI ,

Can we directly import & run this example project given "https://github.com/skyfoundry/haystack-java" code for basic understanding in tomcat server to see how its workflow structure???

Thanks & Regards Gaurav Sahu

GAURAV SAHU Wed 30 Jun

HI Chris,

I am facing 501 error code while using the the javacode in example"https://github.com/skyfoundry/haystack-java", under "HClient.java" It ask (user name ,password and URL) , can you please help me on this?

Thanks &Regards Gaurav Sahu

Chris Breederveld Wed 30 Jun

Hi Gaurav,

Again I would love to know what Haystack server you are working with? NHaystack? SkySpark?

Usually the URL should be of the form "https://some-domain/api/" (don't forget the trailing slash) and the user/pass are just the plaintext credentials you use to log into the application.

GAURAV SAHU Wed 30 Jun

Hi Chris,

we are working with SkySpark &we are passing the argument ("url,user,password) of skypark credential but it gives this below error with 501 (not Implemented ). and one more query regard (HClient.java) file havemn't found the implementation method. Please help me with this Issue.

Exception in thread "main" org.projecthaystack.client.CallNetworkException: org.projecthaystack.client.CallHttpException: 501: Not Implemented

at org.projecthaystack.client.HClient.postString(HClient.java:651)
at org.projecthaystack.client.HClient.postString(HClient.java:611)
at org.projecthaystack.client.HClient.postGrid(HClient.java:605)
at org.projecthaystack.client.HClient.call(HClient.java:597)
at org.projecthaystack.client.HClient.about(HClient.java:184)
at org.projecthaystack.client.HClient.main(HClient.java:770)

Caused by: org.projecthaystack.client.CallHttpException: 501: Not Implemented

at org.projecthaystack.client.HClient.postString(HClient.java:637)
... 5 more

Thanks & Regards Gaurav Sahu

Chris Breederveld Wed 30 Jun

Hi Gaurav,

In SkySpark you will also need to include the project in the URI after /api/. Can you try this code and see what you get?

HClient client = HClient.open("<your-server-url>/api/sys", "<some-user>", "<some-pass>");
client.about();

The "sys" project is a special project in SkySpark that is always available, but has limited functionality, you can also replace this later with your specific project name.

GAURAV SAHU Wed 30 Jun

Hi Chris,

Thanks Chris ,after connecting the URI with sys default functionality " <server uri> /api/sys" it is hitting the sys function.

"Is There any other functionality other than sys to connect?"

Thanks & Regards Gaurav Sahu

Chris Breederveld Wed 30 Jun

Ok, well now all you need to do is replace "sys" with the project name in SkySpark, for example "demo". Then you can use the other calls to get data, for example:

HGrid sites = client.readAll("site")

Chris Breederveld Wed 30 Jun

For any subsequent implementation questions on how to do certain operations or get data, I would suggest to have a look at the SkySpark forum. There are more examples there and more specific SkySpark operations that are not part of the Haystack library.

Login or Signup to reply.