Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
GillesWA
New Member

Get data from web api

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

 

POST /dev/v1/oauth2/token HTTP/1.1
Host: app1pub.smappee.net
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
 
grant_type=password&
client_id=[YOUR_APP_ID]&
client_secret=[YOUR_CLIENT_SECRET]&
username=[USER_NAME]&
password=[USER_PASSWORD]
 
 
Somebody could be help me ??
 
thanks in advance
1 REPLY 1
v-yuezhe-msft
Employee
Employee

@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

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors