Version: 7.0.x

Read Certificates

To read existing certificate records you will need to make a TLS request to the OpenHIM API for the below method and endpoint.

Read all certificates#

Method: GET
Endpoint: {openhim_url}:8080/keystore/ca

Read a specific certificate#

Method: GET
Endpoint: {openhim_url}:8080/keystore/ca/:certificateId

Read the current OpenHIM certificate#

Method: GET
Endpoint: {openhim_url}:8080/keystore/cert

Read validity of server certificate and private key#

Method: GET
Endpoint: {openhim_url}:8080/keystore/validity

Example#

Before we can send our request to the OpenHIM API we need to ensure that we construct our valid HTTP headers to successfully authenticate with the OpenHIM API.

Copy the below code at the bottom of your nodejs script that handles the authentication of the OpenHIM headers as described in the authentication section.

Replace the openhimOptions values with the correct implementation details

// append below code to the "openhim-api.js" script containing the authentication methods.
// This is described within the authentication section
(async () => {
const openhimOptions = {
apiURL: 'https://localhost:8080',
apiEndpoint: '/keystore/ca',
username: '[email protected]',
password: 'openhim-password',
rejectUnauthorized: false
}
const headers = await genAuthHeaders(openhimOptions)
const options = { method: 'GET',
url: `${openhimOptions.apiURL}${openhimOptions.apiEndpoint}`,
rejectUnauthorized: openhimOptions.rejectUnauthorized,
headers: headers
}
request(options, (error, response, body) => {
if (error) throw new Error(error)
console.log({
statusCode: response.statusCode,
body
})
})
})()

The response status code will be 200 if successful.