Retrieving and Verifying API Science Global Variables

In my last blog post I showed how to set API Science variables using my “Set Dog and Meal” API monitor. In this post, I show how to create a new monitor that reads and verifies the status of those parameters.

The “Set Dog and Meal” monitor runs every 60 minutes, setting the following parameter/value pairs:

  • my_dog: Fido
  • my_meal: steak
  • my_status: hungry

To create a monitor to verify this status, I click the “Add Monitor” button on my API Science Dashboard, and define the basic configuration elements:

Here, I’m accessing the API Science Variables API ( using an HTTP GET command to retrieve data from the API. I’ve named the monitor “Dog and Meal Status,” tagged it into my “dogs” category, and the monitor will run every 10 minutes from Washington, D.C.

Clicking the “Test Now” button at this point returns a 401 HTTP return code because the API Science Variables API requires authentication. I click the “Show Settings” link to resolve these issue:

Here, I’ve added an HTTP header with the key Authorization and the value Bearer xxx (where xxx is my API Science API key). [Note: to obtain an API Science API Key, go to your account’s “Settings” page and click on “API Keys.”]

Saving and running this monitor retrieves all the parameters I’ve stored in the API Science Variable API store:

So, the current status is as expected: my planned upcoming meal is steak, I’m hungry, and my dog’s name is “Fido.”

Adding Monitor Validation

Right now, my monitor runs every 10 minutes. When I view the latest results for my “Dog and Meal Status” monitor, I will see successful results if the API responded and returned a list of parameters. But what if the primary value of our product is tied to the existence of a specific parameter?

Let’s say the key item for our product is the “my_meal” parameter. If that parameter doesn’t exist, then our product will be seen as down by most of our customers. How can we verify that the API is not only returning requested data, but is also returning the “my_meal” data that we know is most critical for our customer base?

The API Science platform provides multiple means for validating API responses, including:

  • Response Code – the HTTP status code that is returned with the API’s response text;
  • Regex – a Regular Expression search of the response text;
  • Validate JSON – verifies that the response text is valid JSON;
  • JavaScript – analyzes the response text using user-provided JavaScript;
  • Max Response Time (ms) – declares the API call to have failed if a response is not received after a specified number of milliseconds.

To verify that the response text includes “my_meal” we edit the monitor settings to include a Regex validation:

Now, whenever this monitor runs, it will be considered a failed run if “my_meal” is not included in the response text.

In my next post, I’ll demonstrate cases that test this validation.

–Kevin Farnham

One thought on “Retrieving and Verifying API Science Global Variables

Comments are closed.