Connect the Zencity API to Power BI

Tomer Arad
Tomer Arad
  • Updated

This guide shows you how to load your Zencity data into Power BI using a small built-in query. No special connector or data gateway is required, set it up once and your reports refresh on their own.

Before you start

You'll need three things:

  • A Power BI account. Power BI on the web (app.powerbi.com) or Power BI Desktop, the steps are identical.
  • Your API ID & Secret. These are provided by Zencity. Reach out to your CSM to have them generated for your account.
  • Endpoint details. Some endpoints need extra parameters, for example, a survey group or date range. The Zencity API documentation lists what each one requires.

How the connection works

The Zencity API uses OAuth 2.0 client credentials. The query does this in two automatic steps every time it runs, so you never handle tokens by hand:

  1. Request a token. Your API ID & Secret are sent to the token endpoint, which returns a short-lived access token (valid about an hour).
  2. Call the data endpoint. That token is passed in the request header, and your Zencity data comes back into Power BI.

Power BI's built-in Web connector can't perform this two-step flow on its own, so we use a Blank query with a short Power Query (M) script that does both steps for you.

Set up the connection in Power BI

1. Open Power BI and sign in

Go to app.powerbi.com and sign in. You can also use Power BI Desktop, the steps are the same throughout this guide.

2. Start a new report and choose Get Data

From the homepage, select New report in the top-left corner (or open an existing report), then choose Get Data.

Power BI homepage with the New report and Get Data buttons visible

Figure 1 — Get Data on the Power BI homepage.

3. Select Blank query

In the Choose data source list, select Blank query (bottom-left of the sidebar). This opens the Power Query editor.

The Choose data source list with Blank query highlighted in the sidebar

Figure 2 — Selecting Blank query.

4. Paste the script and add your credentials

Open the Advanced Editor, remove the existing code, and paste the M script from the M scripts section below. Replace the API ID and API Secret placeholders with your own values.

The Blank query editor with the pasted M script

Figure 3 — Pasting the M script into the Blank query editor.

Keep your credentials private. Your API ID and Secret act like a password. Enter them only in Power BI, never paste them into shared chats, emails, or screenshots. Before you share a screenshot of this step, clear the credential fields first.

5. Choose Anonymous authentication

Click Next. When Power BI asks how to connect, choose Anonymous for both api.zencity.io and surveys-api.zencity.io. The script supplies the access token itself, so no other sign-in is needed.

The Connect to data source dialog with Authentication kind set to Anonymous

Figure 4 — Anonymous authentication for both Zencity hosts.

6. Allow the data sources to combine

If Power BI asks about privacy levels, allow the data sources to be combined, setting both to Organizational or Public. The query will then run and return your data.

The M scripts

Your query has two parts: the M Script base, which generates the access token, followed by one data block for the data you want. Paste the M Script first, then add a data block directly below it. Replace the placeholders with your own values; leave everything else exactly as written.

M Script · base

Generates the access token. Every query starts with this.

let
// Generate access token
apiId = "YOUR_API_ID_HERE",
apiSecret = "YOUR_API_SECRET_HERE",
TokenResponse = Json.Document(Web.Contents("https://api.zencity.io", [RelativePath = "api/platform/apiAccess/accessToken", Headers = [#"Content-Type" = "application/json"], Content = Json.FromValue([apiId = apiId, apiSecret = apiSecret])])),
AccessToken = TokenResponse[accessToken],

Listen Categories

Pulls your Listen topic categories. Add this block directly below the M Script base.

// Call specific data point
DataResponse = Json.Document(Web.Contents("https://api.zencity.io", [RelativePath = "api/category/v1/getCategories", Headers = [Authorization = "Bearer " & AccessToken, #"accept" = "application/json"]])),
Output = DataResponse
in
Output

Survey questions list

Returns a list of your survey questions and their IDs. Add this block directly below the M Script base.

// Call specific data point
DataResponse = Json.Document(Web.Contents("https://surveys-api.zencity.io", [RelativePath = "/api/v2/grouped_questions/?question_type=open_ended", Headers = [Authorization = "Bearer " & AccessToken, #"accept" = "application/json"]])),
Output = DataResponse
in
Output

Using other endpoints

To pull a different dataset, keep the M Script base as-is and swap in a different data block — update the host, the RelativePath, and any query parameters to match the endpoint you want. Every endpoint's requirements are listed in the Zencity API documentation:

Notes & troubleshooting

Refreshes keep working automatically

The access token lasts about an hour, but the script fetches a fresh one every time the query runs, so scheduled and manual refreshes keep working without any action from you.

“Invalid credentials” error

Double-check the API ID and Secret, and make sure both URLs were set to Anonymous, not Basic or Organizational, in the authentication dialog.

Scheduled refresh won't save

Scheduled refresh in the Power BI service may require a licensed account. If a refresh can't be saved on the web, set it up in Power BI Desktop instead.

Need more help? Contact Zencity Support at support@zencity.io.

Was this article helpful?

/

Comments

0 comments

Please sign in to leave a comment.