Using REST API in Ambience

1.List item

Sending a report template request via REST API from an application:

//Declare report path and output format

String reportPath = "/ElixirSamples/Report/RML/Pivot%20Table.rml";
String url = "http://localhost:8080/elx/do/eno/re" + reportPath;
String mimeType = "application/pdf";

//Send parameter values in XML format

String xml = "<report mime-type=\""+mimeType+"\">"+
"<parameters>"+
"\n<parameter name=\"Name\">Joanne Tan</parameter>"+
 "\n</parameters>"+
 "\n<return filename=\"report\" disposition=\"attachment\"/>"+
 "\n</report>";

//Log in to the Ambience server

HttpClient httpClient = HttpClients.createDefault();
String encoding = DatatypeConverter.printBase64Binary("admin:sa".getBytes());

//Send POST request to render report template with parameter values

HttpPost httppost = new HttpPost(url);
    httppost.setHeader("Authorization", "Basic " + encoding);
    StringEntity se = new StringEntity(xml.toString(), ContentType.APPLICATION_XML);
    httppost.setEntity(se);
    HttpResponse response = httpClient.execute(httppost);
    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();
    File f = new File("test.pdf");

FileOutputStream fos = new FileOutputStream(f);
IOUtils.copy(is, fos);
    is.close();
    fos.close();

The full Java code sample can be found in the attached rest_api.zip (2.1 MB) .

2.To call an object (report, adhoc report, dashboard, datasource, etc) via REST API call, you can use the following example:

http://localhost:8080/elx/do/eno/re/ElixirSamples/Report/RML/Sub%20Report/Sub%20Report.rml?mode=file&mime-type=application/pdf&OrderID=1002

Explanation of each element in the call:

  • IP address & port: localhost:8080

  • Domain: eno

  • Object type: “re” for report, “adhoc/dashboard” for adhoc dashboard, “adhoc/report” for adhoc report, “ds” for datasource , etc.

  • Path: /ElixirSamples/Report/RML/Sub%20Report/Sub%20Report.rml

  • Mode: mode=file

  • Mime-type: mime-type=application/pdf to render to PDF

  • Lastly is the parameter: OrderID=1002

After that, click at " Render " button to submit the request to render this report.

More samples and explanation can be found in rest_api.zip (2.1 MB) .