SDK
SDK C++ v1.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

This SDK has been deprecated because of stability issues. It is not advised to use it in a production environment.

query #

Base method used to send queries to Kuzzle, following the API Documentation.

This is a low-level method, exposed to allow advanced SDK users to bypass high-level methods.

Signature #

kuzzleio::kuzzle_response* query(const kuzzleio::kuzzle_request& request);

kuzzleio::kuzzle_response* query(
    const kuzzleio::kuzzle_request& request,
    const kuzzleio::query_options& options);

Arguments #

ArgumentTypeDescription
request
kuzzle_request*
API request parameters
options
kuzzleio::query_options*
Query options

request #

Properties required for the Kuzzle API can be set in the kuzzle_request struct. The following properties are the most common.

PropertyTypeDescriptionRequired
controller
const char*
Controller nameyes
action
const char*
Action nameyes
body
const char*
JSON string representing body for this actionno
index
const char*
Index name for this actionno
collection
const char*
Collection name for this actionno
id
const char*
ID for this actionno
volatiles
const char*
JSON string representing additional information to send to Kuzzleno

options #

Additional query options

OptionType
(default)
Description
queuable
bool

(true)
If true, queues the request during downtime, until connected to Kuzzle again

Return #

A kuzzle_response containing the Kuzzle API response. See the API Documentation. The following properties are the most common.

PropertyTypeDescription
request_id
char*
Request unique ID
result
char*
JSON string representing Kuzzle API result
error
char*
Error message
status
int
Request status (eg: 200, 403, etc.)

Exceptions #

Throws a kuzzleio::KuzzleException if there is an error. See how to handle error.

Usage #

try {
  kuzzleio::kuzzle_request request = {0};
  request.controller = "document";
  request.action = "create";
  request.index = "nyc-open-data";
  request.collection = "yellow-taxi";
  request.id = "my-custom-document-id";
  request.body = "{\"trip_distance\": 4.23, \"passenger_count\": 2}";
  kuzzleio::query_options options;
  options.refresh = "wait_for";
  kuzzleio::kuzzle_response* response = kuzzle->query(request, options);
  if (response->status == 200) {
    std::cout << "Document created" << std::endl;
  }
}
catch (kuzzleio::UnauthorizedException& e) {
  std::cerr << "You are not connected" << std::endl;
}
catch (kuzzleio::KuzzleException& e) {
  std::cerr << e.what() << std::endl;
}