cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

Authenticating to the Sophos Central API with Power Query

Authenticating to the Sophos Central API with Power Query

It took me quite some time start authenticating to the Sophos API, so for those searching, here's the Power Query that I use to obtain bearer tokens.

 

First, you'll need to create two parameters called SophosClientID and SophosClientSecret with values of your client ID and client secret from Sophos Central.

Next, you'll need to add a new data source of type 'Blank Query'.

Then, in the Power Query Editior, right click on the new data source and then click 'Advanced Editor'. In the Advanced editor, replace the pre-insterted text with the text below:

let
SophosBearerToken = "Bearer " & (Json.Document(Web.Contents("https://id.sophos.com/api/v2/oauth2/token",
[
Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
Content = Text.ToBinary("grant_type=client_credentials&client_id=" & #"SophosClientID" & "&client_secret=" & #"SophosClientSecret" & "&scope=token")
]
)) [access_token])
in
SophosBearerToken

Click Done, and you should now see a bearer token presented in the Power Query Editor.

 

You can rename this data source something like "SophosBearerToken", and call it in other data source queries using:

#"SophosBearerToken"

 

For example, you can query the Sophos WhoAmI API to get your Partner ID using the Power Query below:

let
PartnerIDQuery = Json.Document(Web.Contents("https://api.central.sophos.com/whoami/v1", [Headers = [#"Authorization"=#"SophosBearerToken"]])),
PartnerID = PartnerIDQuery[id]
in
PartnerID

 

You can reference Sophos' documentation on their API for more useful queries to obtain information from Sophos Central.

 

Hopefully this helps some others! I use this method to authenticate to several APIs that require bearer tokens and it hasn't let me down!

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: Authenticating to the Sophos Central API with Power Query

Thanks for sharing!

I Would mark my answer as a solution so your post may be easily found when people search for the similar topic.

 

Best Regards

Maggie

View solution in original post

1 REPLY 1
Community Support
Community Support

Re: Authenticating to the Sophos Central API with Power Query

Thanks for sharing!

I Would mark my answer as a solution so your post may be easily found when people search for the similar topic.

 

Best Regards

Maggie

View solution in original post

Helpful resources

Announcements

August Community Highlights

Check out a full recap of the month!

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.