Pascal Maugeri

Using Property Manager API to generate an inventory of your digital assets

Blog Post created by Pascal Maugeri Employee on Dec 29, 2015

With Property Manager API (PAPI) you can do nearly everything you are already doing using Akamai portal: reading assets and status, building configuration from scratch and even active configuration.

 

This is my first experiment with this API and I am describing here how to leverage PAPI to get information on the assets (CP Codes, Groups, Configurations, Digital Properties, etc.) that exist in a Luna account. I frequently need indeed to produce an inventory of assets for my customers, and generating such inventory in an automatic is the guarantee that it will stay accurate.

 

1. Create your API Client credentials


Prior to use PAPI you need to create an "API Client" and credentials for your application in Akamai Luna Portal.


You should read and follow the Introduction page on {OPEN} that clearly shows you how to configure and obtain these credentials.


For the impatients, here is a quick visual HOWTO to create your client API and authorisation in Luna:


1. Open the Manage APIs menu from CONFIGURE:

PAPI_blog_1.png


2. Unfold the Luna APIs section and click the gear icon and Add new collection

PAPI_blog_2.png


3. choose a name for this collection such as your name or your department name


4. on the created collection click again on the gear icon and Add New Client, choose a name for your client (eg. PAPI Client)


5. you should see that your API Client is created with an initial credentials set:

PAPI_blog_3.png

6. open the Authorizations tab and click the New Authorization button


7. enter a name (e.g. papi-client-auth) and click Next


8. in the grant selection, find the Property Manager section and choose the desired access type (I suggest you start with a Read-Only access):

PAPI_blog_4.png


9. finally you need to associate this client authorisation with an existing Luna user account.


10. Click Save to create your client authorisation.


11. click the Export button to download a text file with the credentials of your client authorisation:

PAPI_blog_5.png


 

2. Configure your environment

 

As you probably know, the API client authentication is managed through the Akamai {OPEN} Edgegrid Authentication scheme. This authentication scheme is implemented in several languages such as Python, Ruby, Java or Node.js for exemple (see Akamai Technologies {OPEN} · GitHub for all reference implementations). For the purpose of this article, I will use here the Python reference implementation. The library should be installed as explained in the README.rst file (I have chosen to install it using the pip method).

 

In your working directory, create a file .edgerc with a content based on the client authorisation obtained in previous section:

[papi]

host = akab-<HIDDEN_VALUE>.luna.akamaiapis.net

client_token = akab-<HIDDEN_VALUE>

client_secret = <HIDDEN_VALUE>

access_token = <HIDDEN_VALUE>

max-body = 131072

 

 

3. Your first PAPI application: list your groups

 

We are now ready to write our first PAPI application. Note that the Rest API is fully documented with a bunch of example here. I suggest you spend some time reading on the API concepts.

 

The Python application below shows how to obtain the list of all the Groups created in your Luna account. It uses the simple API call "Fetch a List of Groups" that is described in API Reference documentation (see "Groups" section).

 

The following Python snippet creates an EdgeGrid client authentication "session" that will be used later on to interrogate the API backend:

import requests

from akamai.edgegrid import EdgeGridAuth, EdgeRc

from urlparse import urljoin

 

edgerc = EdgeRc('.edgerc')

section = 'papi'

baseurl = 'https://%s' % edgerc.get(section, 'host')

sess = requests.Session()

sess.auth = EdgeGridAuth.from_edgerc(edgerc, section)

...

the previous source code can be extended to make the API call and print the list of the groups retrieved:

...

result = sess.get(urljoin(baseurl, '/papi/v0/groups/'))

jobj = result.json()

for i in jobj['groups']['items']:

  print i['groupName']

 

4. Generate the inventory of your digital assets

 

The object-oriented Python application attached to this post display different views of your groups and a list of the Digital Properties used in the configuration. The application is made of three Python files:

 

  1. The file group.py defines the class Group. The constructor __init__() takes a JSON fragment as parameter, parses it and creates the object. The function displayTree() is a recursive function that display the tree of the groups.
  2. The file property.py defines the class Property. Its constructor works in a similar way as for Group and parses a JSON fragment to create a Property object.
  3. The file papi.py is the main file of the application. It initialises the EdgeGrid authentication, get all the groups of the account, and then it will discover all the Digital Properties used by the configuration. The Digital Properties are listed with the configuration name, version and network (Staging or Production) where there are defined.

 

The application demonstrates the use of the following API calls (see the PAPI Reference page):

  • Fetch a List of Contracts (GET request on /papi/v0/contracts/)
  • Fetch a List of Groups (GET request on /papi/v0/groups/)
  • Fetch a List of Properties (GET request on /papi/v0/properties/)
  • List Property Versions (GET request on /papi/v0/properties/<propertyID>/versions/<version>/hostnames/)

Attachments

Outcomes