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_cred...
  • 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