Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hello,
i try to load data from an API WEB but i have an error :
DataSource.Error: Web.Contents failed to get contents from 'https://app1pub.smappee.net/dev/v1/oauth2/token' (400): Bad Request
Details:
DataSourceKind=Web
DataSourcePath=https://app1pub.smappee.net/dev/v1/oauth2/token
Url=https://app1pub.smappee.net/dev/v1/oauth2/token
Here is my code :
let
// Concatenates the Consumer Key & Consumer Secret and converts to base64
authKey = "Basic " & Binary.ToText(Text.ToBinary("MyID:MySecret"),0),
url = "https://app1pub.smappee.net/dev/v1/oauth2/token",
// Uses the smappee POST oauth2/token method to obtain a bearer token
GetJson = Web.Contents(url,
[
Headers = [ #"Authorization"=authKey,
#"Content-Type"="application/x-www-form-urlencoded;charset=UTF-8"],
Content = Text.ToBinary("grant_type=password&
client_id=[MyID]&
client_secret=[MySecret]&
username=[MyUserName]&
password=[Mypwd]")
]
),
FormatAsJson = Json.Document(GetJson),
// Gets token from the Json response
AccessToken = FormatAsJson[access_token],
AccessTokenHeader = "bearer " & AccessToken,
// Uses the spappee GET search method using the bearer token from the previous POST oauth2/token method
GetJsonQuery = Web.Contents("https://app1pub.smappee.net/dev/v1/servicelocation",
[
Headers = [#"Authorization"=AccessTokenHeader]
]
),
FormatAsJsonQuery = Json.Document(GetJsonQuery)
in
#"FormatAsJsonQuery"
and here is the documentation of the API
Use your application's credentials and the user's credentials to retrieve an access token by sending a HTTP POST message to
https://app1pub.smappee.net/dev/v1/oauth2/token
@GillesWA,
You can use Fiddler to trace your HTTP traffic and see what the detailed message is. And I would recommend you contact smappee support about how to get access token using the API.
There is also a similar blog about how to use Power Query to get data from web API for your reference.
https://www.kasperonbi.com/getting-data-into-power-query-with-the-twitter-search-api-how-to-hack-pq-...
Regards,
Lydia
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!