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 #

Copied to clipboard!
kuzzleio::kuzzle_response* query(const kuzzleio::kuzzle_request& request);

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

Arguments #

Argument Type Description
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.

Property Type Description Required
controller
const char*
Controller name yes
action
const char*
Action name yes
body
const char*
JSON string representing body for this action no
index
const char*
Index name for this action no
collection
const char*
Collection name for this action no
id
const char*
ID for this action no
volatiles
const char*
JSON string representing additional information to send to Kuzzle no

options #

Additional query options

Option Type
(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.

Property Type Description
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 #

Copied to clipboard!
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;
}