Hello Helical Insight Team,
How can we fetch list of canned reports information in a folder using API?
Thank You,
Netta.
Hello Helical Insight Team,
How can we fetch list of canned reports information in a folder using API?
Thank You,
Netta.
Hello Netta,
We can get list of all the files information in a folder with below GET request :
&resource=/1678361644453&recursive=true – folder path
This is fetching all the files and we do not have option to filter out in the API, we should write code then should extract only hcr extension related files:
Sample Java code to call API and extracting canned reports information :
package com.helical;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import org.json.JSONObject;
import com.google.gson.Gson;
import net.sf.json.JSONException;
public class GET_Resourses {
public static void main(String[] args) throws JSONException, IOException {
try {
GET_Resourses.getResources();
} catch (org.json.JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void getResources() throws IOException, org.json.JSONException {
URL urlForGetRequest = new URL("http://localhost:8090/hi-ee/getSolutionResources.html?&resource=/1678361644453&recursive=true&j_username=hiadmin&j_password=hiadmin");
String readLine = null;
JSONObject json = null;
HttpURLConnection conection = (HttpURLConnection)urlForGetRequest.openConnection();
conection.setRequestMethod("GET");
int responseCode = conection.getResponseCode();
if (responseCode == 200) {
System.out.println("responseCode is "+responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(conection.getInputStream()));
StringBuffer response = new StringBuffer();
while ((readLine = in.readLine()) != null)
response.append(readLine);
try {
String str=response.toString().substring(1,response.toString().length());
JSONObject obj = new JSONObject(str);
Gson gson= new Gson();
Map map=gson.fromJson(obj.toString(), Map.class);
ArrayList childrendetails=(ArrayList) map.get("children");
for (int i = 0; i < childrendetails.size(); i++){
String element=childrendetails.get(i).toString();
if(element.contains(".hcr")){ // filtering canned report object
System.out.print("canned Report Object :"+element+ "\n");
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
System.out.println("responseCode is "+responseCode);
}
}
}
Result :
element :{path=1678361644453/0b5e094d-0007-4c84-9323-59b164589f2f.hcr, extension=hcr, permissionLevel=5, name=0b5e094d-0007-4c84-9323-59b164589f2f.hcr, description=0b5e094d-0007-4c84-9323-59b164589f2f.hcr, lastModified=1680102968062, type=file, title=3_cannedReport}
element :{path=1678361644453/0eb4fab4-3af5-477b-b1ea-06e12f4f0668.hcr, extension=hcr, permissionLevel=5, name=0eb4fab4-3af5-477b-b1ea-06e12f4f0668.hcr, description=0eb4fab4-3af5-477b-b1ea-06e12f4f0668.hcr, lastModified=1680102922160, type=file, title=1_cannedreport}
element :{path=1678361644453/8d5377ee-6e35-4d8d-bd4b-e2ea42f2a093.hcr, extension=hcr, permissionLevel=5, name=8d5377ee-6e35-4d8d-bd4b-e2ea42f2a093.hcr, description=8d5377ee-6e35-4d8d-bd4b-e2ea42f2a093.hcr, lastModified=1680102992681, type=file, title=4_cannedReport}
element :{path=1678361644453/a1ba8e38-6668-4e25-b3eb-3d2c7ccdff28.hcr, extension=hcr, permissionLevel=5, name=a1ba8e38-6668-4e25-b3eb-3d2c7ccdff28.hcr, description=a1ba8e38-6668-4e25-b3eb-3d2c7ccdff28.hcr, lastModified=1680102949068, type=file, title=2_cannedreport}
Thank You,
Helical Insight.