0

Using JAVA, I am trying to republish a dashboard to a particular User. It returns me HTTP status 500. Below is the code for it.

String sisenseURL = surl; // This is correct URL to POST API for PUBLISH


String urlParameters = "force=true";
 byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 );
 int postDataLength = postData.length;

 URL url = new URL( sisenseURL );
 HttpURLConnection conn= (HttpURLConnection) url.openConnection();

 conn.setDoOutput(true);
 conn.setInstanceFollowRedirects(false);
 conn.setRequestMethod("POST");
 conn.setRequestProperty("Content-Type", "application/json");
 conn.setRequestProperty("Accept", "application/json");
 conn.setRequestProperty("Content-Length", Integer.toString(postDataLength ));
 conn.setRequestProperty("Authorization", accessToken);
 conn.setUseCaches(false);



 try(DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
 wr.write( postData );
 }



 BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
 final StringBuffer stringBuffer = new StringBuffer();
 String line;
 while ((line = in.readLine()) != null) {
 stringBuffer.append(line);
 }
 in.close();

The request runs file with POSTMAN as well as with the Swagger UI for Sisense.

Any help would be greatly appreciated.

TIA

Ashutosh

Virgil
  • 3,022
  • 2
  • 19
  • 36
Ashutosh Vyas
  • 419
  • 4
  • 17

1 Answers1

1

Here is a java example for sisense V6.7 of updating dashboard shares using the rest API You didnt share your payload so not sure if thats the problem, but the example below worked for me. I took the sendPostRequest code from here

import java.io.*;
import java.net.*;

public class Runner {
    public static void main(String[] args){
        try {
            //Dashboard shares payload
            String payload = "{\"sharesTo\":[{\"shareId\":\"58504c5221785b627cb4361d\",\"type\":\"user\",\"subscribe\":false},{\"shareId\":\"58505ba6ec4df9701a000019\",\"type\":\"user\",\"rule\":\"view\",\"subscribe\":false}]}";


            String str = sendPostRequest(getDashboardUrl(), payload);

            System.out.println("Done");
        }
        catch (RuntimeException e){

        }
    }

    public static String sendPostRequest(String requestUrl, String payload) {
        try {
            URL url = new URL(requestUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            connection.setDoInput(true);
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Accept", "application/json");
            connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
            connection.setRequestProperty("Authorization", getAuthorization());
            OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
            writer.write(payload);
            writer.close();
            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            StringBuffer jsonString = new StringBuffer();
            String line;
            while ((line = br.readLine()) != null) {
                jsonString.append(line);
            }
            br.close();
            connection.disconnect();
            return  jsonString.toString();
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());

        }

    }
    public static String getDashboardUrl(){
        //Sisense domain
        String baseURL = "http://localhost:8081";

        return baseURL + "/api/shares/dashboard/5850511cec4df9701a000013";
    }

    public  static String getAuthorization(){
        return "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiNTg1MDRjNTIyMTc4NWI2MjdjYjQzNjFkIiwiYXBpU2VjcmV0IjoiOGUwZDIyOWItY2VmMS0xYTE4LTNhYWEtYmY1ZmE1ZmNkNTExIiwiaWF0IjoxNTE1MDEzMzkxfQ.zgx0Nv8YztfM2rm5WTCnJ0R6C_n5V-HNkEZgAcINfs4";
    }
}
avi.tavdi
  • 305
  • 2
  • 4
  • 17
  • I am not looking to update the dashboard shares. That I have already done. Once you update the share, in order for the dashboard to be visible to the user, you need to PUBLISH it again. That's what the problem area is. When we call the publish API, its a post request with no payload. Any idea how you do that ? – Ashutosh Vyas Jan 05 '18 at 06:04