API

Q&A API Documentation.

Note: All API needs an API Key to be sent in the request headers. Please follow these steps to generate an API Key.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class GetSystems {

    public static void main(String[] args) throws Exception {
        String url = System.getenv("DATAWORKZ_SERVICE") != null ? System.getenv("DATAWORKZ_SERVICE") : "https://ragapps.dataworkz.com"; // Replace ragapps.dataworkz.com with actual service host
        url = url + "/api/qna/v1/systems";
        String authorizationHeader = "SSWS " + System.getenv("DATAWORKZ_API_TOKEN");

        if (System.getenv("DATAWORKZ_API_TOKEN") == null) {
            System.err.println("System environment variable DATAWORKZ_API_TOKEN not set.");
            System.exit(1);
        }

        // Create URL object
        URL apiUrl = new URL(url);

        HttpURLConnection connection = null;
        // Open a connection
        try {
            connection = (HttpURLConnection) apiUrl.openConnection();

            // Set the request method to GET
            connection.setRequestMethod("GET");

            // Set request headers
            connection.setRequestProperty("accept", "application/json");
            connection.setRequestProperty("Authorization", authorizationHeader);

            // Get the response code
            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);

            // Read the response
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
                String line;
                StringBuilder response = new StringBuilder();
                while ((line = reader.readLine()) != null) {
                    response.append(line);
                }

                // Print the response
                System.out.println("Response: " + response.toString());
            }

        } finally {
            // Close the connection
            if (connection != null) {
                connection.disconnect();
            }
        }
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class GetSystem {

    public static void main(String[] args) throws Exception {
        String url = System.getenv("DATAWORKZ_SERVICE") != null ? System.getenv("DATAWORKZ_SERVICE") : "https://ragapps.dataworkz.com"; // Replace ragapps.dataworkz.com with actual service host
        url = url + "/api/qna/v1/systems/{systemId}";

        String systemId = System.getenv("DATAWORKZ_SYSTEM_ID");
        String authorizationHeader = "SSWS " + System.getenv("DATAWORKZ_API_TOKEN");

        if (systemId == null || System.getenv("DATAWORKZ_API_TOKEN") == null) {
            System.err.println("All Environment variables - DATAWORKZ_SYSTEM_ID, DATAWORKZ_API_TOKEN are not set. ");
            System.exit(1);
        }
        String result = sendHttpGetRequest(url, systemId, authorizationHeader);
        System.out.println(result);
    }

    private static String sendHttpGetRequest(String apiUrl, String systemId, String authorizationHeader) throws IOException {
        String apiUrlWithSystemId = apiUrl.replace("{systemId}", systemId);

        // Create URL object
        URL url = new URL(apiUrlWithSystemId);

        // Open a connection
        HttpURLConnection connection = null;
        try {
            connection = (HttpURLConnection) url.openConnection();

            // Set the request method to GET
            connection.setRequestMethod("GET");

            // Set request headers
            connection.setRequestProperty("accept", "application/json");
            connection.setRequestProperty("Authorization", authorizationHeader);

            // Get the response code
            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);

            // Read the response
            StringBuilder response = new StringBuilder();
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    response.append(line);
                }
            }
            return response.toString();
        } finally {
            // Close the connection
            if (connection != null) {
                connection.disconnect();
            }
        }
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class GetLLMProviders {

    public static void main(String[] args) throws Exception {
        String apiUrl = System.getenv("DATAWORKZ_SERVICE") != null ? System.getenv("DATAWORKZ_SERVICE") : "https://ragapps.dataworkz.com"; // Replace ragapps.dataworkz.com with actual service host
        apiUrl = apiUrl + "/api/qna/v1/systems/{systemId}/llm-providers";
        String systemId = System.getenv("DATAWORKZ_SYSTEM_ID");
        String authorizationHeader = "SSWS " + System.getenv("DATAWORKZ_API_TOKEN");

        if (systemId == null || System.getenv("DATAWORKZ_API_TOKEN") == null) {
            System.err.println("All Environment variables - DATAWORKZ_SYSTEM_ID, DATAWORKZ_API_TOKEN are not set. ");
            System.exit(1);
        }

        String result = sendHttpGetRequest(apiUrl, systemId, authorizationHeader);
        System.out.println(result);
    }

    private static String sendHttpGetRequest(String apiUrl, String systemId, String authorizationHeader) throws IOException {
        String apiUrlWithSystemId = apiUrl.replace("{systemId}", systemId);

        // Create URL object
        URL url = new URL(apiUrlWithSystemId);

        // Open a connection
        HttpURLConnection connection = null;
        try {
            connection = (HttpURLConnection) url.openConnection();

            // Set the request method to GET
            connection.setRequestMethod("GET");

            // Set request headers
            connection.setRequestProperty("accept", "application/json");
            connection.setRequestProperty("Authorization", authorizationHeader);

            // Get the response code
            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);

            // Read the response
            StringBuilder response = new StringBuilder();
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    response.append(line);
                }
            }
            return response.toString();
        } finally {
            // Close the connection
            if (connection != null) {
                connection.disconnect();
            }
        }
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

public class GetAnswer {

    public static void main(String[] args) throws Exception {
        if (args.length == 0) {
            System.err.println("Query must be passed as argument to this program.");
            System.exit(1);
        }
        String apiUrl = System.getenv("DATAWORKZ_SERVICE") != null ? System.getenv("DATAWORKZ_SERVICE") : "https://ragapps.dataworkz.com"; // Replace ragapps.dataworkz.com with actual service host
        apiUrl = apiUrl + "/api/qna/v1/systems/{systemId}/answer?questionText={questionText}&llmProviderId={llmProviderId}";
        String systemId = System.getenv("DATAWORKZ_SYSTEM_ID");
        String authorizationHeader = "SSWS " + System.getenv("DATAWORKZ_API_TOKEN");
        String questionText = args[0];
        String llmProviderId = System.getenv("DATAWORKZ_LLM_ID");

        if (systemId == null || llmProviderId == null || System.getenv("DATAWORKZ_API_TOKEN") == null) {
            System.err.println("System Environment variables are not set. Need to set DATAWORKZ_SYSTEM_ID, DATAWORKZ_LLM_ID, DATAWORKZ_API_TOKEN");
            System.exit(1);
        }

        String result = sendHttpGetRequest(apiUrl, systemId, questionText, llmProviderId, authorizationHeader);
        System.out.println(result);
    }

    private static String sendHttpGetRequest(String apiUrl, String systemId, String questionText, String llmProviderId, String authorizationHeader) throws IOException {
        String apiUrlWithParams = apiUrl
                .replace("{systemId}", systemId)
                .replace("{questionText}", URLEncoder.encode(questionText, "UTF-8"))
                .replace("{llmProviderId}", URLEncoder.encode(llmProviderId, "UTF-8"));

        // Create URL object
        URL url = new URL(apiUrlWithParams);

        // Open a connection
        HttpURLConnection connection = null;
        try {
            connection = (HttpURLConnection) url.openConnection();

            // Set the request method to GET
            connection.setRequestMethod("GET");

            // Set request headers
            connection.setRequestProperty("accept", "application/json");
            connection.setRequestProperty("Authorization", authorizationHeader);

            // Get the response code
            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);

            // Read the response
            StringBuilder response = new StringBuilder();
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    response.append(line);
                }
            }
            return response.toString();
        } finally {
            if (connection == null) {
                // Close the connection
                connection.disconnect();
            }
        }
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

public class GetSearchResults {

    public static void main(String[] args) throws Exception {
        if (args.length == 0) {
            System.err.println("Query must be passed as argument to this program.");
            System.exit(1);
        }
        String apiUrl = System.getenv("DATAWORKZ_SERVICE") != null ? System.getenv("DATAWORKZ_SERVICE") : "https://ragapps.dataworkz.com"; // Replace ragapps.dataworkz.com with actual service host
        apiUrl = apiUrl + "/api/qna/v1/systems/{systemId}/search?query={questionText}";
        String systemId = System.getenv("DATAWORKZ_SYSTEM_ID");
        String authorizationHeader = "SSWS " + System.getenv("DATAWORKZ_API_TOKEN");
        String questionText = args[0];

        if (systemId == null || System.getenv("DATAWORKZ_API_TOKEN") == null) {
            System.err.println("System Environment variables are not set. Need to set DATAWORKZ_SYSTEM_ID, DATAWORKZ_API_TOKEN");
            System.exit(1);
        }

        String result = sendHttpGetRequest(apiUrl, systemId, questionText, authorizationHeader);
        System.out.println(result);
    }

    private static String sendHttpGetRequest(String apiUrl, String systemId, String questionText, String authorizationHeader) throws IOException {
        String apiUrlWithParams = apiUrl
                .replace("{systemId}", systemId)
                .replace("{questionText}", URLEncoder.encode(questionText, "UTF-8"));

        // Create URL object
        URL url = new URL(apiUrlWithParams);

        // Open a connection
        HttpURLConnection connection = null;
        try {
            connection = (HttpURLConnection) url.openConnection();

            // Set the request method to GET
            connection.setRequestMethod("GET");

            // Set request headers
            connection.setRequestProperty("accept", "application/json");
            connection.setRequestProperty("Authorization", authorizationHeader);

            // Get the response code
            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);

            // Read the response
            StringBuilder response = new StringBuilder();
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    response.append(line);
                }
            }
            return response.toString();
        } finally {
            if (connection == null) {
                // Close the connection
                connection.disconnect();
            }
        }
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class GetFilters {

    public static void main(String[] args) throws Exception {
        String url = System.getenv("DATAWORKZ_SERVICE") != null ? System.getenv("DATAWORKZ_SERVICE") : "https://ragapps.dataworkz.com"; // Replace ragapps.dataworkz.com with actual service host
        url = url + "/api/qna/v1/systems/{systemId}/filters";

        String systemId = System.getenv("DATAWORKZ_SYSTEM_ID");
        String authorizationHeader = "SSWS " + System.getenv("DATAWORKZ_API_TOKEN");

        if (systemId == null || System.getenv("DATAWORKZ_API_TOKEN") == null) {
            System.err.println("All Environment variables - DATAWORKZ_SYSTEM_ID, DATAWORKZ_API_TOKEN are not set. ");
            System.exit(1);
        }
        String result = sendHttpGetRequest(url, systemId, authorizationHeader);
        System.out.println(result);
    }

    private static String sendHttpGetRequest(String apiUrl, String systemId, String authorizationHeader) throws IOException {
        String apiUrlWithSystemId = apiUrl.replace("{systemId}", systemId);

        // Create URL object
        URL url = new URL(apiUrlWithSystemId);

        // Open a connection
        HttpURLConnection connection = null;
        try {
            connection = (HttpURLConnection) url.openConnection();

            // Set the request method to GET
            connection.setRequestMethod("GET");

            // Set request headers
            connection.setRequestProperty("accept", "application/json");
            connection.setRequestProperty("Authorization", authorizationHeader);

            // Get the response code
            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);

            // Read the response
            StringBuilder response = new StringBuilder();
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    response.append(line);
                }
            }
            return response.toString();
        } finally {
            // Close the connection
            if (connection != null) {
                connection.disconnect();
            }
        }
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpExample {

    public static void main(String[] args) {
        String apiUrl = "https://{genAI}.dataworkz.com"; // Replace {genAI} with actual service host
        apiUrl = apiUrl + "/api/qna/v1/systems/{systemId}/questionshistory";
        String systemId = "123"; // Replace with the actual system ID
        String authorizationHeader = "SSWS xxxxxxx"; // Replace with the actual authorization token

        try {
            String result = sendHttpGetRequest(apiUrl, systemId, authorizationHeader);
            System.out.println(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static String sendHttpGetRequest(String apiUrl, String systemId, String authorizationHeader) throws IOException {
        String apiUrlWithSystemId = apiUrl.replace("{systemId}", systemId);

        // Create URL object
        URL url = new URL(apiUrlWithSystemId);

        // Open a connection
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        // Set the request method to GET
        connection.setRequestMethod("GET");

        // Set request headers
        connection.setRequestProperty("accept", "application/json");
        connection.setRequestProperty("Authorization", authorizationHeader);

        // Get the response code
        int responseCode = connection.getResponseCode();
        System.out.println("Response Code: " + responseCode);

        // Read the response
        StringBuilder response = new StringBuilder();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
            String line;
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
        }

        // Close the connection
        connection.disconnect();

        return response.toString();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpExample {

    public static void main(String[] args) {
        String apiUrl = "https://{genAI}.dataworkz.com"; // Replace {genAI} with actual service host
        apiUrl = apiUrl "/api/qna/v1/systems/{systemId}/questions/{questionId}";
        String systemId = "123"; // Replace with the actual system ID
        String questionId = "456"; // Replace with the actual question ID
        String authorizationHeader = "SSWS xxxxxxx"; // Replace with the actual authorization token

        try {
            String result = sendHttpGetRequest(apiUrl, systemId, questionId, authorizationHeader);
            System.out.println(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static String sendHttpGetRequest(String apiUrl, String systemId, String questionId, String authorizationHeader) throws IOException {
        String apiUrlWithIds = apiUrl
                .replace("{systemId}", systemId)
                .replace("{questionId}", questionId);

        // Create URL object
        URL url = new URL(apiUrlWithIds);

        // Open a connection
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        // Set the request method to GET
        connection.setRequestMethod("GET");

        // Set request headers
        connection.setRequestProperty("accept", "application/json");
        connection.setRequestProperty("Authorization", authorizationHeader);

        // Get the response code
        int responseCode = connection.getResponseCode();
        System.out.println("Response Code: " + responseCode);

        // Read the response
        StringBuilder response = new StringBuilder();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
            String line;
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
        }

        // Close the connection
        connection.disconnect();

        return response.toString();
    }
}

To generate an API key for interacting with these APIs, please follow the steps outlined in the "API key generation" section.

Last updated