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
Highlighted
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
Highlighted
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 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Upcoming Events

Upcoming Events

Wondering what events you could join or have an event to promote yourself? Check out our Upcoming Events.

Community Summit Australia – Join Online!

Community Summit Australia – Join Online!

Be a part of the leading Microsoft Business Applications digital event, curated for the APAC community.