Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
102 | |
53 | |
21 | |
12 | |
12 |