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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
EduardoRocha96
New Member

(415): Unsupported Media Type - Json

Hey guys, Can you help me? I'm trying to generate the accesstoken for integration via API, but I keep getting the same error message.

 

() =>
let
body = Json.FromValue([
grantType = "client_credentials",
clientId = "clientId",
clientSecret = "clientSecret"
]),
response = Json.Document(
Web.Contents(
url,
[
Headers = [
#"Content-Type" = "application/json"
],
Content = body
]
)
)
in
response[accessToken]

 

(415): Unsupported Media Type
Details:
DataSourceKind=Web
DataSourcePath=https://merchant-api.ifood.com.br/authentication/v1.0/oauth/token
Url=https://merchant-api.ifood.com.br/authentication/v1.0/oauth/token

1 ACCEPTED SOLUTION
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

@EduardoRocha96  - Json.FromValue is incorrect.  You need to define a text string and convert it to a binary file type.

let
    url = "https://merchant-api.ifood.com.br/authentication/v1.0/oauth/token",
    #"Client Id" = "c9daf25e-6b3d-4e7b-9eed-36792df10be9",
    #"Client Secret" = "l4jkpmdp4axfyn60olr8685s85f8yvq3hugf5h1jztq65tjx8mbg209ljcj4bjxd5vg13s1k21gm869oyaa5y509az47ll8buy3",
    body = "grantType=client_credentials&clientId=" & #"Client Id" & "&clientSecret=" & #"Client Secret",
    #"body to binary" = Text.ToBinary( body ),
    response = Web.Contents(
            url,
            [ 
                Headers = [ #"Content-Type" = "application/x-www-form-urlencoded" ],
                Content = #"body to binary"
            ]
        ),
    open = Json.Document( response ),
    token = open[accessToken]
in
    token

View solution in original post

4 REPLIES 4
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

@EduardoRocha96  - Json.FromValue is incorrect.  You need to define a text string and convert it to a binary file type.

let
    url = "https://merchant-api.ifood.com.br/authentication/v1.0/oauth/token",
    #"Client Id" = "c9daf25e-6b3d-4e7b-9eed-36792df10be9",
    #"Client Secret" = "l4jkpmdp4axfyn60olr8685s85f8yvq3hugf5h1jztq65tjx8mbg209ljcj4bjxd5vg13s1k21gm869oyaa5y509az47ll8buy3",
    body = "grantType=client_credentials&clientId=" & #"Client Id" & "&clientSecret=" & #"Client Secret",
    #"body to binary" = Text.ToBinary( body ),
    response = Web.Contents(
            url,
            [ 
                Headers = [ #"Content-Type" = "application/x-www-form-urlencoded" ],
                Content = #"body to binary"
            ]
        ),
    open = Json.Document( response ),
    token = open[accessToken]
in
    token

Thanks! It Worked!

Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @EduardoRocha96 

If think you need to change the Content Type from "application/json" to "application/x-www-form-urlencoded".  Please refer to the following documentation for more information.  iFood Developer | Referências .  Sorry I can help anymore because it is difficult to test without access.

I tried changing the content-type, but now another error is appearing:

(400) - Bad request

I have trial access if you need it 🙂

 

clientId = "c9daf25e-6b3d-4e7b-9eed-36792df10be9",
clientSecret = "l4jkpmdp4axfyn60olr8685s85f8yvq3hugf5h1jztq65tjx8mbg209ljcj4bjxd5vg13s1k21gm869oyaa5y509az47ll8buy3"

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.