Help Center/ Conversational Bot Service/ API Reference/ QABot APIs/ Other APIs/ Obtaining Questions Prompted When a User Enters a Question
Updated on 2023-06-06 GMT+08:00

Obtaining Questions Prompted When a User Enters a Question

Function Description

This API is used to obtain the list of questions prompted when a user enters a question.

URI

POST https://{endpoint}/v1/{project_id}/qabots/{qabot_id}/suggestions

Table 1 Path parameters

Parameter

Mandatory

Type

Description

endpoint

Yes

String

Endpoint, which is the request address for calling an API.

The endvertex varies depending on the service and region. You can obtain it from Endpoints.

project_id

Yes

String

Project ID, which is used for resource isolation. For details, see Obtaining a Project ID.

qabot_id

Yes

String

Q&A bot ID, which is in the UUID format. For example, 303a0a00-c88a-43e3-aa2f-d5b8b9832b02.

This parameter is displayed in the Q&A Bot Name/ID column of the QABot console.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

Used to obtain the permission to call APIs. The value of X-Subject-Token in the Interface for Obtaining a Token response header is the token.

Content-Type

Yes

String

Message body type (format). The value is application/json.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

question

Yes

String

Question entered by a user. If an empty string is entered, no data is returned. Enter 1 to 512 characters.

top

No

Integer

Maximum number of prompted questions. The default value is 5. The value ranges from 1 to 10.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

questions

Array of strings

List of recommended questions.

Status code: 400

Table 5 Response body parameters

Parameter

Type

Description

error_code

String

Error code returned when the API fails to be called. This parameter is not included when the API is successfully called.

error_msg

String

Error message returned when the API fails to be called. This parameter is not included when the API is successfully called.

Example Requests

  • Example request
    POST https://{endpoint}/v1/41551a23c2be484cb0070631e323ee52/qabots/b36a01da-7fc2-43f8-8990-218e57a94420/suggestions
    
    Request Header:
        Content-Type: application/json
        X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
    
    Request Body:
    {
        "question":" Cloud desktop",
        "top":2
    }
  • Python request code example
    import requests
    url = "https://{endpoint}/v1/{project_id}/qabots/{qabot_id}/suggestions"
    token = "Actual token value obtained by the user"
    headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}
    body = {"question":"Desktop cloud","top":2}
    
    response = requests.post(url, headers=headers, json=body, verify=False)
    print(response.text)
  • Java request code example
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    public class CBSDemo {
    
        public void cbsDemo() {
            try {
                //Replace endpoint, projectId, and qabot_id with the actual ones.
                URL url = new URL("https://{endpoint}/v1/{project_id}/qabots/{qabot_id}/suggestions");
                String token = "Actual token value obtained by the user";
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod("POST");
                connection.setDoInput(true);
                connection.setDoOutput(true);
                connection.addRequestProperty("Content-Type", "application/json");
                connection.addRequestProperty("X-Auth-Token", token);
    
                //Input parameters
                String body = "{\"question\":\"Desktop cloud\",\"top\":2}";
    
                OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
                osw.append(body);
                osw.flush();
                InputStream is = connection.getInputStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                while (br.ready()) {
                    System.out.println(br.readLine());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public static void main(String[] args) {
            CBSDemo CBSDemo = new CBSDemo();
            CBSDemo.cbsDemo();
        }
    }

Example Responses

Status code: 200

Example of a successful response

{
    "questions":[
       "Failed to open the cloud desktop.",
       "Failed to log in to the cloud desktop."
    ]
}

Status code: 400

Example of a failed response

{
  "error_code": "CBS.0022",
  "error_msg": "question can not be null"
}

Status Code

For details about status codes, see Status Code.

Error Code

For details about error codes, see Error Code.