Forum Discussion

EduardoRocha96's avatar
EduardoRocha96
New Member
2 years ago
Solved

(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

  • Anonymous's avatar
    Anonymous
    2 years ago

    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

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    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
  • Anonymous's avatar
    Anonymous
    Not applicable

    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.

    • EduardoRocha96's avatar
      EduardoRocha96
      New Member

      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"