I have access to some telemetry data in azure (specifically all the API calls for customers using a mobile app). I have used the httr package in R to request the data over a 3 minute period and assess the response like so (obviously have my own app ID and key which I have not included below):
install.packages("httr")
library(httr)
r1 <- GET("https://api.applicationinsights.io/v1/apps/application-ID/query?timespan=PT0.05H&query=requests", add_headers("X-Api-Key" = "my-unique-key"))
r1
####### response object ########
# Response [https://api.applicationinsights.io/v1/apps/application-ID/query?timespan=PT0.05H&query=requests]
# Date: 2018-01-11 15:55
# Status: 200
# Content-Type: application/json; charset=utf-8
# Size: 84.7 kB
In the environment window, I can see r1 is a list of 10 and that there are 84,652 raw values:
I can also use the content function to see I have a list of 1:
r2 <- content(r1)
I have two questions really:
1) How do I make sense of these outputs in the environment window? What do they tell me about the structure of my data (I think it's JSON based on content type description)
2) Is there a way to retrieve the data and get it into tabular format (a data frame)? I don't understand how to query the data. I read this article, but couldn't apply it to my data: https://tclavelle.github.io/blog/r_and_apis/
Any help would be appreciated.
UPDATE 19/01/18
I used jalind's suggestion. See below for code and outputs:
library(httr)
library(jsonlite)
r1 <- GET("https://api.applicationinsights.io/v1/apps/application-ID/query?timespan=PT0.05H&query=requests", add_headers("X-Api-Key" = "my-unique-key"))
#convert to a character string
r2 <- rawtoChar(r1$content)
#check the class is character
class(r2)
# now extract JSON from string object
r3 <- fromJSON(r2)
# convert to a data frame - this returns a data frame with columns called name, columns and rows
x <- as.data.frame(r3[[1]])
# column headings data frame (there are 37 columns - see example of first 3 columns below):
c <- as.data.frame(x$columns)
# name type
# timestamp datetime
# id string
# source string
# data frame with 37 columns and all rows of telemetry data (only showing first 4 columns of this data frame):
r <- as.data.frame(x$rows)
# X1 X2 X3 X4
# 1 2018-01-19T10:29:25.4Z |aticCNxxxx=.f83assss_ <NA> GET /Cards/Cardtype1
# 2 2018-01-19T10:29:30.226Z |tX6Xz0xxxxx=.27cxcxae_ <NA> GET /AddressLookup/Address
# 3 2018-01-19T10:29:45.327Z |OgfPbicLues=.f83a9a1f_ <NA> POST /Account/MobileDevice
# 4 2018-01-19T10:29:46.078Z |V5MwpXXxxxxx=.f83axxxx_ <NA> GET /Cards/Cardtype1
# 5 2018-01-19T10:30:00.427Z |Jok8wxxxxxx=.7be33aaa_ <NA> GET /cards/Cardtype1