This article explains how to pull data from the Phishing Tackle API into Power BI. There are two ways to do this: a simple Web request for a single API call, or an Advanced Query that can combine multiple API calls into one report.
Before you start
To make an API call, you will need your API Key, User ID and Organisation ID. All three are available within the platform under 'Setup' > 'Organisation' > 'Settings' > 'API'.
For step-by-step instructions on generating your API Key and finding your IDs, please see Getting Started with the Phishing Tackle API.
A full list of available endpoints can be found in the Phishing Tackle API 1.0 documentation.
Option 1: Using Get Data > Web
This is the quickest way to retrieve data from a single endpoint.
- In Power BI, select the drop-down next to the 'Get Data' button.
- Select 'Web'.
- Open the API documentation, find the endpoint you want to request information from, and copy the request URL.
-
Back in Power BI, select 'Advanced' on the web request window, then enter the URL and the following header values:
- Api_Key: your API Key
- UserId: your User ID
- OrganisationId: your Organisation ID
Note: The URL will require you to enter your account details, for example:
CampaignID = the ID of your training course or campaign
SubOrganisationID = your Organisation ID - Click 'OK'.
- The requested information will then be retrieved.
Option 2: Using an Advanced Query (recommended)
The Get Data > Web option above is limited to one API call at a time. Using Power BI’s Advanced Editor, you can write a query that does much more. A single query can make multiple API calls, for example retrieving a list of all your training courses and then automatically fetching the results for each one. The results from every call are then merged and shaped into a single, report-ready table.
How to create an Advanced Query
- In Power BI, select 'Get Data' and then 'Blank Query'.
- In the Power Query Editor, select 'Advanced Editor' from the ribbon.
- Delete the existing text and paste in your query (see the example below).
- Replace the placeholder values for ApiKey, UserId and OrgId with your own details.
- Click 'Done'. If you are prompted for credentials, select 'Anonymous' and click 'Connect', as your details are already supplied in the request headers.
- Click 'Close & Apply' to load the data into your report.
Example: training status for every course
This example query:
- Retrieves a list of all your training courses.
- Retrieves the recipient (delegate) details for each course.
- Combines the results and pivots them into one table, with a row per recipient and a column per course showing their course status.
let
ApiKey = "YOUR_API_KEY",
UserId = "YOUR_USER_ID",
OrgId = "YOUR_ORGANISATION_ID",
Headers = [
#"Api_Key" = ApiKey,
#"UserId" = UserId,
#"OrganisationId" = OrgId,
#"Accept" = "application/json"
],
// Step 1: get all course IDs
CampaignList = Json.Document(
Web.Contents(
"https://mspapi.phishingtackle.com/api/TrainingCampaigns?orgId=" & OrgId,
[ Headers = Headers ]
)
),
CampaignIds = List.Transform(CampaignList, each Text.From([id])),
// Step 2: for each course ID, fetch delegate detail safely, field by field
GetDelegatesForCourse = (courseId as text) as table =>
let
Response = try Json.Document(
Web.Contents(
"https://mspapi.phishingtackle.com/api/TrainingCourseDelegateDetail?subOrgId=" & OrgId & "&courseId=" & courseId,
[ Headers = Headers ]
)
) otherwise null,
Result = if Response = null or List.IsEmpty(Response) then
#table({"firstname","lastname","emailAddress","managerName","managerEmailAddress","courseStatus","CourseName"}, {})
else
let
FirstItem = Response{0},
CourseDescription = if FirstItem[courseDescription] = null then "Course " & courseId else FirstItem[courseDescription],
Delegates = FirstItem[delegates],
SafeRows = List.Transform(Delegates, each [
firstname = Record.FieldOrDefault(_, "firstname", null),
lastname = Record.FieldOrDefault(_, "lastname", null),
emailAddress = Record.FieldOrDefault(_, "emailAddress", null),
managerName = Record.FieldOrDefault(_, "managerName", null),
managerEmailAddress = Record.FieldOrDefault(_, "managerEmailAddress", null),
courseStatus = Record.FieldOrDefault(_, "courseStatus", null),
CourseName = CourseDescription
]),
ToTable = Table.FromRecords(SafeRows, {"firstname","lastname","emailAddress","managerName","managerEmailAddress","courseStatus","CourseName"})
in
ToTable
in
Result,
// Step 3: run for every course ID and combine into one table
AllTables = List.Transform(CampaignIds, each GetDelegatesForCourse(_)),
Combined = Table.Combine(AllTables),
RenamedLong = Table.RenameColumns(Combined, {
{"firstname", "First Name"},
{"lastname", "Last Name"},
{"emailAddress", "Email"},
{"managerName", "Manager Name"},
{"managerEmailAddress", "Manager Email"}
}),
AddKey = Table.AddColumn(RenamedLong, "RecipientKey", each [First Name] & " " & [Last Name] & " (" & [Email] & ")"),
Pivoted = Table.Pivot(
Table.SelectColumns(AddKey, {"RecipientKey", "First Name", "Last Name", "Email", "Manager Name", "Manager Email", "CourseName", "courseStatus"}),
List.Distinct(AddKey[CourseName]),
"CourseName",
"courseStatus"
),
RemoveKey = Table.RemoveColumns(Pivoted, {"RecipientKey"})
in
RemoveKeyYou can adapt this approach to any endpoint in the API documentation.
Please let us know if you require any further assistance, you can contact our support team by clicking here. Or by sending an email to support@phishingtackle.com