Get Observepoint API Data with Python

Here we make a call to the Observepoint API and inspect the results before loading into the PostgreSQL database.  It is also translated into JSON. The python code to grab the data from Observepoint is available along with other languages in their documentation: https://docs.api.observepoint.com/

#!/usr/bin/python
#usr 20180807

import http.client
import json

def getJourneys():
print(':getJourneys() start')

conn = http.client.HTTPSConnection("api.observepoint.com")
payload = "{}"
headers = { 'authorization': "api_key YOURAPIKEY" }
conn.request("GET", "/v2/web-journeys", payload, headers)
res = conn.getresponse()
data = res.read()
de_data = data.decode("utf-8")
jdata = json.loads(de_data)

for rownum, drow in enumerate(jdata, 1):
print('drow:' + str(rownum))
for dfield in drow:
print(dfield + ':', end='')
print(drow.get(dfield))

if rownum == 1:
break

print(':getJourneys() end')

if __name__ == '__main__':
print(':__main__() start')
getJourneys()
print(':__main__() end')

Result:

All posts in this ETL series:
Install PostgreSQL Database
Simple Data Model
Create Tables in PostgreSQL Database
Getting JSON API data with Python
Inserting JSON data into Postgres with Python

Leave a Reply

Your email address will not be published. Required fields are marked *