Prerequisites


The Plan

This guide shows how to make a simple dig IP address lookup request using resources from the Akamai Intelligent Platform™. First, the client requests the locations in the Akamai network that are capable of running the dig utility. The app will then selects a location from the response and submit a dig request to get the IP address information for developer.akamai.com.

API Call Sequence

  • GET /diagnostic-tools/v1/locations
  • GET /diagnostic-tools/v1/dig?hostname={hostname}&location={location}&queryType={queryType}

You can view the documentation for the diagnostic-tools API to get more information and to see other tools that it exposes.


Making API Calls

During the previous steps, you authorized and configured credentials for the diagnostic tools utility. During this step you will make calls to this API.

API Calls


HTTPie

If you chose to set up HTTPie during the initial setup, you can make calls directly to the API once you have satisfied the prerequisites above.

Making a call with HTTPie is simple. The instructions are the same however you set it up.

We’ll start with the locations call:

$ http --auth-type edgegrid -a default: :/diagnostic-tools/v1/locations

Next, let’s make a call to the dig command itself. In this case we need to set some query parameters as shown in the diagnostic-tools documentation.

$ http --auth-type edgegrid -a default: :/diagnostic-tools/v1/dig hostname==developer.akamai.com queryType==A location=="Tokyo, Japan"

Using Sample Code

To use the sample code, let’s run the application.

You should be in the same directory you used for Setup Your Environment and Configure your Credentials.

Run the diagnostic_tools.py script:

$ python diagnostic_tools.py

Requesting locations that support the diagnostic-tools API.

There are 62 locations that can run dig in the Akamai Network
We will make our call from Mountprospect, United States

Running dig from Mountprospect, United States

; <<>> DiG 9.8.1-P1 <<>> developer.akamai.com -t A
...

;; Query time: 209 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Sep 24 20:04:58 2014
;; MSG SIZE  rcvd: 304

$

Analyzing the Results

The first call the application makes is to the /diagnostic-tools/v1/locations resource which returns a JSON object containing a list of Akamai locations that can run the diagnostic-tools API.

{
  "locations": [
    "Miami, United States",
    ...
    "Oakbrook, United States"
  ],
  "errorString": null
}

It then randomly selects a location from this list and submits a GET request to the /diagnostic-tools/v1/dig resource. The dig results come back in another JSON object:

{
  "dig": {
    "authoritySection": [
      ...
      {
        "preferenceValues": null,
        "domain": "dscb.akamaiedge.net.",
        "recordType": "NS",
        "value": "n4dscb.akamaiedge.net.",
        "ttl": "7200",
        "recordClass": "IN"
      }
    ],
    "errorString": null,
    "hostname": "developer.akamai.com.",
    "result": "\n; <<>> DiG 9.8.1-P1 <<>> developer.akamai.com -t A\n;; global options: +cmd\n;; Got answer:\n;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5665\n;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 8, ADDITIONAL: 0\n\n;; QUESTION SECTION:\n;developer.akamai.com.\t\tIN\tA\n\n;; ANSWER SECTION:\ndeveloper.akamai.com.\t300\tIN\tCNAME\tdeveloper.akamai.com.edgekey.net.\ndeveloper.akamai.com.edgekey.net. 21600\tIN CNAME e8952.dscb.akamaiedge.net.\ne8952.dscb.akamaiedge.net. 20\tIN\tA\t23.58.155.95\n\n;; AUTHORITY SECTION:\ndscb.akamaiedge.net.\t7200\tIN\tNS\tn0dscb.akamaiedge.net.\ndscb.akamaiedge.net.\t7200\tIN\tNS\tn3dscb.akamaiedge.net.\ndscb.akamaiedge.net.\t7200\tIN\tNS\tn1dscb.akamaiedge.net.\ndscb.akamaiedge.net.\t7200\tIN\tNS\tn2dscb.akamaiedge.net.\ndscb.akamaiedge.net.\t7200\tIN\tNS\tn5dscb.akamaiedge.net.\ndscb.akamaiedge.net.\t7200\tIN\tNS\tn6dscb.akamaiedge.net.\ndscb.akamaiedge.net.\t7200\tIN\tNS\tn7dscb.akamaiedge.net.\ndscb.akamaiedge.net.\t7200\tIN\tNS\tn4dscb.akamaiedge.net.\n\n;; Query time: 140 msec\n;; SERVER: 127.0.0.1#53(127.0.0.1)\n;; WHEN: Wed Sep 24 20:03:40 2014\n;; MSG SIZE  rcvd: 304\n\n",
    "answerSection": [
      ...
      {
        "preferenceValues": null,
        "domain": "e8952.dscb.akamaiedge.net.",
        "recordType": "A",
        "value": "23.58.155.95",
        "ttl": "20",
        "recordClass": "IN"
      }
    ],
    "queryType": "A"
  }
}

Congratulations!

You’ve completed your first Akamai OPEN API call! Now you are ready to explore more of the APIs offered in the OPEN API Catalog.

Now What?

We’ve taken you through the basics, now it’s your turn. Here are some suggestions:

  • Extend the sample client to suit your needs—perhaps implement mtr functionality into diagnostic_tools.py.
  • Download an open source OPEN API Client that matches your preferred development language.
  • Explore the APIs available in the Akamai OPEN API Catalog.
  • Discuss your results in the Akamai Developer Community.
  • Contribute to the Akamai API ecosystem.