Skip to main content
Splunk Lantern

Data validation for API responses

You might want to not only confirm that an API response code is expected but that the right data comes back in the right format when doing the following:

Prerequisites 

In order to execute this procedure in your environment, the following data, services, or apps are required:

Example

When a Splunk user hits the endpoint for their check with an API key, you want to make sure that a “200 OK” response code is returned, along with the data set for the correct ID that matches the endpoint. To validate this, create an external, synthetic test to hit the check endpoint at a set frequency from multiple locations.

  1. Make a request with an API key to Splunk API’s endpoint for real browser check data.
  2. Assert that the response code contains the value ‘200.’
  3. Extract the check ID from the JSON using JSON path.
  4. Assert that the check ID extracted from the JSON path is the expected value.

clipboard_e25231a05b0cbb1159b2b00c6159fb3db.png

Results

This simple user flow helps test:

  • Availability: The check will fail if the API returns a response code that’s not 200 OK.
  • Data Format: If the data comes back from the API in a format other than JSON then the step to extract a value using JSON path will fail the check.
  • Data Quality: If you’re able to extract a value for the ID but it doesn’t match the expected value, then the assert step will fail the check.
  • Was this article helpful?