Sisense - REST API - 重新发布不起作用 + 500 内部服务器错误



使用JAVA,我正在尝试将仪表板重新发布给特定用户。它返回我的 HTTP 状态 500。下面是它的代码。

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();

该请求使用 POSTMAN 以及 Sisense 的 Swagger UI 运行文件。

任何帮助将不胜感激。

蒂亚

阿舒托什

下面是使用 rest API 更新仪表板共享的 sisense V6.7 的 Java 示例您没有共享您的有效负载,所以不确定这是否是问题所在,但下面的示例对我有用。我从这里拿走了发送帖子请求代码

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";
    }
}

相关内容

  • 没有找到相关文章

最新更新