whibr08

Tech Tip - CA Mobile App Analytics: MAA Reporting API Example

Discussion created by whibr08 Employee on Jul 8, 2015
Latest reply on Sep 14, 2015 by kopja02

CA Mobile Application Analytics (MAA) Tuesday Tip by Bryan Whitmarsh, Sr Principal Technical Consultant for Tuesday, July 7, 2015

 

In this Tuesday tip I’ll walk you through how to access MAA’s Secure Reporting APIs. The MAA platform has been designed to be flexible. Ok, so maybe the MAA Server can’t reach down and touch its keyboard, but flexible in the sense that it can be adapted and easily integrated into a customer’s environment; meeting their specific mobile analytics needs. Maybe a customer wants to have their own custom analytics dashboard or integrate certain analytics data collected by MAA into other systems (maybe even a non-CA system…;). This is all possible leveraging MAA’s Secure Reporting APIs.   

 

First off, let’s get a feel for these API’s by viewing them being called in the MAA Console from your favorite browser. My favorite browser these days is Chrome (had to stop using Netscape…;) To view the MAA Reporting API calls, open up the browser’s console. For Chrome, you click on the three horizontal line icon next to the address bar and then select “More tools -> JavaScript Console”. 

Image_01.png

Then in the console on the bottom, click on the “Network” tab. This will show you all the network calls the browser is making. If you login to your MAA Console and click on the “Crashes” menu you can view the sample crash_summary REST API call we are going to use in this tip (mouse over the call to see the full http syntax). Note: If you try and copy/paste this url into your browser address you won’t get a response because you first need proper authentication to make the calls (shown in MAA_Reporting_API_Sample.sh content below).

Image_02.jpg

Another great resource for learning about the MAA Secure Reporting APIs is the “HELP” screen within the MAA Console.

Image_03.jpg

Once the “HELP” screen is open, click on the “REPORTING API” menu. Click on the “crashes:Crashes” operation and then on the “GET” button next to the “/crashes/crash_summary” operation. You can enter in parameters (required parameters are in BOLD) and then click on “Try it out!” to see the syntax of the REST API call.

Image_04.jpg

Note: Because localhost is the server name used for the “Try it out!” feature, unless you are running this from your MAA Server, you will not get a response. But this feature is useful for understanding which reporting APIs are available and their correct syntax.

 

Ok, I think we are ready to create our Secure Rest Call and send it off for a response. Attached is a sample shell script file (MAA_Reporting_API_Sample.sh). This script needs to be run from a machine that can run the Unix shell like the MacOS Terminal, or from the command line of a Unix/Linux machine. Before we can run it, we need to customize it for the specific MAA server you are using. Open up the attached MAA_Reporting_API_Sample.sh file and add your MAA Server/App values for the following variables; USER, COHORT, PASS, SERVER, AGGREGATION, START_DATE, END_DATE, and APP_ID. After you have done this you can save and run the script.

 

---- Content Start: MAA_Reporting_API_Sample.sh---

#This script is used to call the Secure MAA crash_summary Reporting API

 

#Replace the values for the ones below with your values

 

#Server Variables

USER=YOUR_USER_NAME

COHORT=YOUR_TENANT_NAME

PASS=YOUR_USER_PASSWORD

SERVER=https://your_server_address.com

 

#Required Parameters for crash_summary reporting API

AGGREGATION=day         #this value can be hour, day, or month

START_DATE=2015-07-01   #year-month-day

END_DATE=2015-07-07     #year-month-day

 

#Optional Parameter for carsh_summary reporting API

APP_ID=YOUR_APP_ID

 

#Converting your Tenant name to base64 (text) for making the below JSON REST calls

cohort=`echo $COHORT | openssl enc -base64`

echo

#Sending the Servername, User, and base64 tenant name to the screen so you can see it...

echo Using Server : $SERVER with User : $USER and cohort : $COHORT

echo

 

#Before we can access the MAA Secure Reporting APIs we need to get an authentication token

TOKEN=`curl -s  -X POST -H "Authorization: Basic $cohort" -H "Accept-Language: en_US" -d "grant_type=PASSWORD&username=$USER&password=$PASS" $SERVER/ess/security/v1/token  | json tkn`

curl   -v -X POST -H "Authorization: Basic $cohort" -d "grant_type=PASSWORD&username=$USER&password=$PASS" $SERVER/ess/security/v1/token

 

#Sending the token to the screen so you can see one was received

echo "TOKEN:" $TOKEN

 

#Exiting the script if we don't get a token because you can't continue with this script if you don't have a token

if [ -z "$TOKEN" ]; then

echo no token

exit 1

fi

 

#For the below REST calls we are going to get the data for a specific tenant so we are going to create a base64 token including the necessary tenant info

ENC_AUTHZ=`echo \{\"tkn\":\"$TOKEN\",\"t\":\"$COHORT\"\}    | openssl enc -base64 -A`

#Sending the token to the screen so you can see one was created

echo 'ENC_AUTHZ' $ENC_AUTHZ

echo

 

#Calling the Secure MAA Reporting API using a curl command to receive crash_summary information

#The curl command is a tool to transfer data to/from a server

#The -s = silent mode, -S will show any errors, -H allows us to pass the required authentication token as a header with the call

#The "| json" will format the return data so it's more readable, if you don't have json installed you will get an error so you can remove this (or install json)

curl -s -H "Authorization: Bearer $ENC_AUTHZ" "$SERVER/mdo/v1/crashes/crash_summary?aggregation=$AGGREGATION&start_date=$START_DATE&end_date=$END_DATE&app_id=$APP_ID" | json

 

echo

---- Content End: MAA_Reporting_API_Sample.sh---

 

Additional details regarding the CA MAA Reporting APIs can be found on the public CA Mobile App Analytics Product Wiki https://wiki.ca.com/dashboard.action under the “Reference-Use the REST APIs” section.

 

Please add your own sample code in various languages to this post.

Outcomes