Solve API problems fast with Runscope. Learn More →

Testing Email Notifications using Runscope and Context.IO

By Darrel Miller on .

A common function of many APIs is the ability to send notifications via email.  However, this type of interaction can be tricky to test.  Fortunately there are services available that can make an email inbox available via HTTP API requests and Runscope Radar is ideal for querying those APIs.

This post demonstrates how you can use Runscope to trigger an email being sent and then verify the email was actually received using the Context.IO service. 

Sending An Email

As a surrogate for an API to test, I chose to use the Mandrill API to send an email.  

To be able to identify that a particular email has been delivered we need to have some kind of identifying marker.  To do this I created an initial variable and then assigned a random string to it.  

The marker string is then added to the email subject line.   



Waiting For Delivery

In order to allow time for the email to arrive in the inbox I inserted a 30 second pause in the test.


Confirming Delivery

Context.IO provides an API over Gmail and Google Apps inboxes.  You will probably want to setup a separate Gmail account for testing notifications.  Once you sign up for a Context.IO account you are provided with an OAuth 1.0 Consumer Key and Consumer Secret.  Runscope can take care of generating the OAuth Authorization header using these values.

Within the Context.IO site you will need to connect the Gmail account.  Once that is done you can use their interactive documentation pages to test the API and discover the URL to the mailbox inbox.

In order to confirm delivery we must query the email account inbox and check for a subject line with the marker value.  Here is the script based assertion to do that.       

var data = JSON.parse(response.body);

var found = false;
for (var messageidx in data) {
    var subject = data[messageidx].subject;
    var marker = variables.get("marker");
    if (subject.indexOf(marker) > 0) {
        found = true;
assert(found,"Found email containing marker");

In some scenarios it may not be possible to inject a marker value into the subject line of the email. In these cases different techniques may be required to identify the delivered email.  In some cases, simply checking the date and time received may be sufficient.

If you do not already have a Runscope account then why not head over to our free sign up page and start testing those hard to test parts of your API.


Comparing HTTP Requests Using Runscope

By Darrel Miller on .

It is a fairly common requirement when working with Web APIs to be able to identify the differences between two requests.  Maybe a call has started failing, or you want to compare the responses from two different versions of an API to see what has changed.

Runscope makes it very simple to select two requests in the Traffic Inspector and get a side by side "diff" of the request and response headers and body.

Here's a short screencast that shows how to do it.


Cross-Checking Your APIs Against JSON Schema Using Runscope

By Neil Mansilla on .

Photo of first indoor ice hockey game. (source: Wikipedia)

Photo of first indoor ice hockey game. (source: Wikipedia)

A popular format for RESTful API schema formats is JSON Schema. It's a well designed spec that is extensible, easy to read and write, and supports canonical and inline referencing/dereferencing. We’ve recently shipped an update that gives Runscope Radar assertion support for JSON Schema validation by way of the Chai assertion library.

So, what exactly does that mean? It means that you’re able to use Runscope to validate your API responses against a defined JSON Schema. A few examples of validation include:

  • insuring method responses are structured properly

  • checking for existence of required keys

  • verifying that values are of a certain type (e.g. integer, string, etc.) and within constraints (min/max)

Runscope currently supports validation against the v4 draft spec of JSON Schema. Lets run through an example.

Step 1: Set the Schema Definition

The method we’re testing pulls down the roster of players on a hockey team. The top level object is an array named roster. Each array item of roster contains an object named player, which has three required properties: player_number, guid and name. So, in this first step, we provide our Runscope test with the JSON schema.

We’ll store the schema as global variable via the Initial Script (a script that executes before the request steps begin). At line 1, we’ll store the JSON Schema into a local variable named rosterResponse. In order to make this globally accessible, we’ll store an object using variables.set on line 25. (link to source)

Note: This sample schema uses canonical references (see reference to player object). They're quite handy, especially when you're working in a larger schema with repeated use of an object.

Step 2: Add Request Step and Script Assertion

Our Radar test has one GET request that returns the team roster. We’ll write our assertion in JavaScript that will validate the response body against the JSON Schema we defined in the previous step.

He Shoots.. He Scores!

When we run the test, the results show our schema validation test as passing.

To try this out on your own account, or to read more about JSON Schema and the Chai JSON-Schema module, see the links below:

If you need assistance setting up validation against your JSON Schema or general help with Runscope contact our support team at any time.

Update Addendum: Improvements to Scripted Assertions

As a side note, scripted assertions have also been improved! Fully evaluated details of each scripted assertion are written out on the test results, Also, all scripted assertions are executed, even if one of them fails. Previous to this update, the moment one assertion failed, the rest of the script would be skipped.

For a list of all updates to Runscope, visit our Change Log.

Categories: howto

Runscope 25 Kearny St, 5th Floor San Francisco, CA, 94108 United States

Hypermedia, Past, Present and Future

By Darrel Miller on .

Hypermedia APIs are beginning to enter the mainstream of API development.  For developers trying to get up to speed on hypermedia there are a dizzying array of terminology and choices. This blog post gives an overview of the hypermedia space, giving some perspective on where we have come from, what has been tried, what has worked, what has not, where the industry is headed and what questions remain unresolved.  Read more here...

Categories: api, hypermedia

Everything is going to be 200 OK