Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi All
Please can I ask for assistance - new to PowerBI and Oauth 2 issues to access an API - see below erro and M language query
DataSource.Error: Web.Contents failed to get contents from 'https://api.crowdstrike.com/oauth2/token' (415): Unsupported Media Type
Details:
DataSourceKind=Web
DataSourcePath=https://api.crowdstrike.com/oauth2/token
Url=https://api.crowdstrike.com/oauth2/token
let
url = "https://api.crowdstrike.com/oauth2/token",
body = "{ ""client_id"": ""xxxxxx"", ""client_secret"": ""xxxxxxxxxx""}",
tokenResponse = Json.Document(Web.Contents(url,[Headers = [#"Content-Type"="application/json"], Content = Text.ToBinary(body) ] )),
AccessToken = tokenResponse[access_token],
AccessTokenHeader = "Bearer " & AccessToken,
data_url = "https://api.crowdstrike.com/devices/queries/devices/v1",
Source = "{
""authorization"": """& AccessTokenHeader & """,
""content-type"": ""application/json""
}",
GetGroups = Json.Document(
Web.Contents(
data_url,
[
Headers = Json.Document(data_body)
]
)
),
#"Converted to Table" = Table.FromRecords({Source}),
#"Expanded meta" = Table.ExpandRecordColumn(#"Converted to Table", "meta", {"query_time", "pagination", "powered_by", "trace_id"}, {"meta.query_time", "meta.pagination", "meta.powered_by", "meta.trace_id"}),
#"Expanded meta.pagination" = Table.ExpandRecordColumn(#"Expanded meta", "meta.pagination", {"offset", "limit", "total"}, {"meta.pagination.offset", "meta.pagination.limit", "meta.pagination.total"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded meta.pagination",{{"meta.query_time", type number}, {"meta.pagination.offset", Int64.Type}, {"meta.pagination.limit", Int64.Type}, {"meta.pagination.total", Int64.Type}, {"meta.powered_by", type text}, {"meta.trace_id", type text}, {"resources", type any}, {"errors", type any}})
in
#"Changed Type"
Thanks Mark
Solved! Go to Solution.
Hi @markvanwyk
(415): Unsupported Media Type - means the API doesn't like the format of the data you're sending. Specifically, CrowdStrike's OAuth2 token endpoint expects the data to be sent as application/x-www-form-urlencoded, not as JSON. Try this:
let
url = "https://api.crowdstrike.com/oauth2/token",
body = "client_id=xxxxxx&client_secret=xxxxxxxxxx",
tokenResponse = Json.Document(
Web.Contents(
url,
[
Headers = [#"Content-Type" = "application/x-www-form-urlencoded"],
Content = Text.ToBinary(body)
]
)
),
AccessToken = tokenResponse[access_token],
AccessTokenHeader = "Bearer " & AccessToken,
data_url = "https://api.crowdstrike.com/devices/queries/devices/v1",
GetGroups = Json.Document(
Web.Contents(
data_url,
[
Headers = [
#"Authorization" = AccessTokenHeader,
#"Content-Type" = "application/json"
]
]
)
)
in
GetGroups Fixes applied
Changed Content-Type to application/x-www-form-urlencoded for the token request.
Changed the body format to URL-encoded string: client_id=...&client_secret=...
Removed unnecessary JSON formatting for headers.
Please giver a thumbs up and mark as solved if this helps, thanks!
Thanks a mill - working well
Hi @markvanwyk ,
Thanks for reaching out to the Microsoft fabric community forum.
The 415 unsupported media type error is often a result of simple misconfiguration in header or payload structure. Please ensure that your Content-type is correct and your header is without any issue.
Small changes can lead to significant API interaction improvements.
I hope this information helps. Please do let us know if you have any further queries.
Thank you
This is coming from the OAuth2 token request, and it means that the server is rejecting the request because the content type or format of the request body is incorrect. The CrowdStrike API expects the token request to be sent as application/x-www-form-urlencoded, not JSON. So use the following code.
let
url = "https://api.crowdstrike.com/oauth2/token",
body = "client_id=xxxxxx&client_secret=xxxxxxxxxx&grant_type=client_credentials",
tokenResponse = Json.Document(Web.Contents(url, [
Headers = [#"Content-Type" = "application/x-www-form-urlencoded"],
Content = Text.ToBinary(body)
])),
AccessToken = tokenResponse[access_token],
AccessTokenHeader = "Bearer " & AccessToken,
data_url = "https://api.crowdstrike.com/devices/queries/devices/v1",
GetGroups = Json.Document(Web.Contents(data_url, [
Headers = [
#"Authorization" = AccessTokenHeader,
#"Content-Type" = "application/json"
]
])),
#"Converted to Table" = Table.FromRecords({GetGroups})
in
#"Converted to Table"
Hi @markvanwyk
(415): Unsupported Media Type - means the API doesn't like the format of the data you're sending. Specifically, CrowdStrike's OAuth2 token endpoint expects the data to be sent as application/x-www-form-urlencoded, not as JSON. Try this:
let
url = "https://api.crowdstrike.com/oauth2/token",
body = "client_id=xxxxxx&client_secret=xxxxxxxxxx",
tokenResponse = Json.Document(
Web.Contents(
url,
[
Headers = [#"Content-Type" = "application/x-www-form-urlencoded"],
Content = Text.ToBinary(body)
]
)
),
AccessToken = tokenResponse[access_token],
AccessTokenHeader = "Bearer " & AccessToken,
data_url = "https://api.crowdstrike.com/devices/queries/devices/v1",
GetGroups = Json.Document(
Web.Contents(
data_url,
[
Headers = [
#"Authorization" = AccessTokenHeader,
#"Content-Type" = "application/json"
]
]
)
)
in
GetGroups Fixes applied
Changed Content-Type to application/x-www-form-urlencoded for the token request.
Changed the body format to URL-encoded string: client_id=...&client_secret=...
Removed unnecessary JSON formatting for headers.
Please giver a thumbs up and mark as solved if this helps, thanks!
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 8 | |
| 7 | |
| 6 | |
| 6 | |
| 5 |