Connecting to PredictHQ APIs with Microsoft Excel
Learn how to connect PredictHQ data to Microsoft Excel using APIs.
Last updated
Was this helpful?
Learn how to connect PredictHQ data to Microsoft Excel using APIs.
Last updated
Was this helpful?
, , , , ,
, Consumer Packaged Goods, , Leisure, Travel and Tourism, Marketing and Advertising, , Restaurants, , and Others
The data used in this guide is based on a popular location, in our case San Francisco City as a whole. Please change the location from San Francisco to the location you want to look at.
Below are the main steps involved in this guide:
Building Report Parameters around a Location
Example Parameters for this Guide
Select an Input method
API connection
View events data in Excel
Requirements:
API:
Microsoft Excel
Date: user-defined, this tutorial uses a 3-month period from January 1st to March 31st 2024
Event State: Active and Predicted
PHQ Attendance: attended events only - filtered to events with an attendance of at least 1
This guide provides details on how to load PredictHQ's event data into Microsoft Excel using the Events API. The examples have been provided for Excel running in Microsoft Windows. In this tutorial we'll show you how to connect to the API and load data into a Spreadsheet. Start by creating a new empty Spreadsheet in Microsoft Excel.
Time zone parameter (active.tz) filters results based on that given time zone, even though date results are returned in UTC.
Limit parameter allows for more results returned per “page” which allows for faster loading, rather than the default 10 per page.
With this API query string, event data can start to be loaded into Microsoft Excel.
First, create a new Spreadsheet. Click on the Data tab and choose Get Data as shown below:
Choose the Advanced tab, not the Basic default. Because the PredictHQ API is Bearer token authorized, the Advanced tab must be selected to include the API Access Token request header.
Add the HTTP request header with the following information:
URL parts: our created Events API URL from the above: https://api.predicthq.com/v1/events/?active.gte=2024-01-01&active.lt=2024-04-01&active.tz=America/Los_Angeles&category=community,conferences,concerts,expos,festivals,performing-arts,sports&state=active,predicted&phq_attendance.gte=1&place.scope=5391959&limit=500
HTTP request header parameters:
Put Authorization
in the first field
The filled-out information should look like this (except that api_key should be replaced with your actual api_key)
After clicking “OK”, the Data Transformation page will open where data shaping options can be made before building the report.
Rename the Query to something relevant, as it defaults to the connection URL string parameters which does not look neat. We recommend renaming it to “PredictHQ Connection”, but if you name it something else you will need to change the Power Query below too.
In order to transform the columns, open Power Query and paste the code below to format and expand some columns for easy use. To do this, go to the Advanced Editor for this Query, right click on the Query name under Queries and click Advanced Editor:
Replace the entire existing Power Query code with the one below, changing the 2 lines (Lines 4 and 8) that refer to ‘[api_token]’ with the PHQ API Access Token used previously.
The code in the advanced editor should look like the screen shot below:
Click Close & Apply and wait for the data transformation to finish processing through multiple API pages.
After this step the data is now ready to start building a report with, as it has been successfully loaded and transformed in Microsoft Excel. You should see a Spreadsheet like that shown below:
You now have a connection to the API that you can refresh to get updated data.
Categories: community, conferences, concerts, expos, festivals, performing-arts, sports - these are our
Location: San Francisco city (place ID )
Location could be substituted for a specific latitude and longitude relating to an individual store, or could be scoped even wider depending on need. We suggest utilizing our to hone in on a specific shop location and pull only events within a more accurate radius based on those results. For now, we will look at the citywide events in San Francisco as our example.
PredictHQ has a number of different APIs that can be used to build reports, in this example, we will stick to the Events API. Starting this process assumes a PredictHQ API access token has been created by following the .
Microsoft Excel will connect using the URL for the : but, query parameters must be added to this URL for the Excel connection, in line with the parameters outlined in the .
Following these parameters and the documentation we will end up with a URL string like the one below:
Note: Scope uses the Place ID (geonames ID) for San Francisco (see our ). If you were looking for events happening around a business location you would use the with the latitude and longitude of your business location and the radius from the suggested radius API.
See also our for details on how to query the Events API for events impacting your locations.
Put Bearer <api_token>
in the field on the right of the first field with Authorization
. where <api_token>
will be replaced with your PHQ API Access Token. Just replace <api_token>
with your actual API Access Token. Leave the ‘Bearer ’ part in. Below is what the fields will look like once you have put in your API key.
\
This code expands out the 'impact_patterns' column (see in our technical documentation for more information) and filters it to accommodation and actual attendance distribution. It renames some essential columns. It also accounts for our API pagination, making sure all results are returned. It is an involved process with multiple steps - the Power Query below is the final output of this multi-stage transformation.