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:
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!
Go to Solution.
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.
View solution in original post
Check out a full recap of the month!
Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.