Power bi access to serviceM8

I am in the process of putting a dashboard together in PowerBI - the data is sourced from both ServiceM8 and Buz.

The BUZ side is working fine.

The serviceM8 is not :frowning:

I have successfully got data back from serviceM8 using power automate. ServiceM8 requires an application key x-api-key and basic authentication. Like I say this works perfectly in power automate.

In PBI I have made a blank query and using advanced editor put the following code in;

let
// Replace with your actual token
access_token = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”,

// API endpoint example: Get all jobs
Source = Json.Document(
Web.Contents(
https://api.servicem8.com/api_1.0/job.json”,
[
Headers = [
#“x-Api-Key” = access_token,
Accept = “application/json”
]
]
)
),

// Convert JSON to table
ToTable = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
Expanded = Table.ExpandRecordColumn(ToTable, “Column1”)
in
Expanded

Like I say, I have to use basic authentication however when I run the query it chucks a wobbly saying "‘x-Api-Key’ header is only supported when connecting anonymously. "

If I change the authentication to anonymous, the query fails (Authentication error).

In my mind I have a workaround - which may or may not work - write a small power automate and use that to retrieve the data from serviceM8 - however I would prefer to go directly.

Any advice, thoughts, special prayers you can offer me?

Stan

Hi Stan,

For the ServiceM8 REST API, the documented “private application” approach is to authenticate by sending your API key in the X-API-Key header on every request.

A couple of ServiceM8-specific checks based on your example:

  • Make sure you’re using an API Key created in ServiceM8 under Settings → API Keys (rather than an OAuth access token).
  • The “List all Jobs” endpoint is GET https://api.servicem8.com/api_1.0/job.json, and the API key is supplied via the X-Api-Key request header.

If you’re currently combining X-API-Key with HTTP Basic Auth in Power BI, it’s worth trying the request using only the documented header approach (and matching the header name exactly as shown in our docs).

If your setup requires OAuth instead, ServiceM8 also supports OAuth 2.0, and you can call the API by sending the access token as Authorization: Bearer {access_token}.

Also, make sure you don’t post your API key in screenshots or code samples publicly.

If you’re still getting a 401 after switching to the X-API-Key approach, email support@servicem8.com with the key redacted and the full error text, and we’ll investigate.

Thanks,
Cody