Accessing campaigns#

Authenticate#

The first step is to establish a secure connection to the 4insight.io services. This can be achieved starting a “User Session”:

from fourinsight.api import UserSession

session = UserSession()
# Follow instructions to authenticate

Note

fourinsight.api.UserSession is intended for single-user interactive sessions, such as coding in notebooks. For non-interactive applications, consider to use the fourinsight.api.ClientSession instead, which does not require any user interaction, but expects client_id and client_secret. client_id and client_secret are applications specific credentials that are set up on request. Contact us and we will help you.

Now we are ready to proceed.

Retrieve campaign data#

To initiate a client:

from fourinsight.campaigns import Client

client = Client(session)

The client object can be used to get a list of available campaigns in 4insight using the overview() method:

campaigns = client.overview()

the overview() method returns a dataframe containing all available campaigns and relevant metadata for each, for example campaignID, start time, end time and so on.

To retrieve data for a particular campaign, use the get() method:

campaign = client.get('campaign_guid')

The campaign object have methods that “mirror” the sections/tabs in Campaigns in 4insight.io.

Display general information:

campaign.general()

Get list of events:

campaign.events()

Get list of sensors:

campaign.sensors()

Some methods also support some filtering. For instance, to filter the list of sensors by Position:

lmrp_sensors = campaign.sensors(value="LMRP", by="Position")