Example code
If you are accessing the zeuz base API directly, you can adapt the following example code for your own purposes.
Before you begin
Before you start to adapt the example code for your own purposes, ensure that you have read the following pages, so you know what you need to set up:
This example code covers two of the tasks from API authentication overview: 3. Log in to zeuz and generate a session key and 4. Generate a sign-hash to attach to your API requests as well as additional functionality, as listed below:
- Define data structures
- Example 1: Define data structures.
- Log in and generate a session key
- Example 2: Generate a nonce and timestamp, and formulate a cURL request to the
auth_login
endpoint. - Example 3: Log in to zeuz by sending the cURL request formulated in Example 2 and generate a session key.
- Example 2: Generate a nonce and timestamp, and formulate a cURL request to the
- Generate a sign-hash, check the logged in session is valid, and send a request to an API endpoint
- Example 4: Generate a sign-hash, send a JSON packet to the
auth_check
API endpoint, and parse the return value to see if the logged in session is valid or invalid. If it’s valid, send a new cURL request to a zeuz API endpoint.
- Example 4: Generate a sign-hash, send a JSON packet to the
These examples use OpenSSL for hashing with secure hash algorithm SHA3 and base64 encoding, and the libcurl library for HTTP requests.
Note: You can also see separate example snippets in C++ for the two main tasks in API login and Sign-hash generation.
Examples
Example 1: Define data structures (C++)
|
|
Example 2: Generate a nonce and timestamp, and formulate a cURL request to the auth_login
endpoint (C++)
|
|
Example 3: Log in to zeuz by sending the cURL request formulated in Example 2 and generate a session key (C++)
|
|
Example 4: Generate a sign-hash, send a JSON packet to the auth_check
API endpoint, and parse the return value to see if the logged in session is valid or invalid. If it’s valid, send a new cURL request to a zeuz API endpoint (C++)
|
|
2021-may-12 Page added with editorial review.