Forum Discussion

fdanielsouza's avatar
fdanielsouza
Helper I
6 years ago

How to send a GET method with content data with M?

Hello! I'm having trouble to get a response from an API which receives GET methods but also asks for content using M (trying to wrap it in a Custom Connector). I can get a sample response on it with curl by using:

 

curl -X GET "https://api.salaovip.com.br/reports/0005?page=1&limit=100" ^
-H "Content-Type:application/json" ^
-H "Authorization: MY_API_KEY" ^
-d "{\"params\": [{ \"name\": \"inicio\", \"value\": \"01/01/2020\" }, { \"name\": \"fim\", \"value\": \"03/02/2020\" }]}"

 

So, when I try to do it with M it doesn't work, I guess Web.Contents automatically send it as a POST method when I use a header with "Content-Type", since I receive a 405 status code with "Method not allowed". I tried to use the WebAction.Request(WebMethod.Get, url, options) function, but in the Visual Studio it won't leave the Credential Set screen, and always gives me an "We haven't been given permissions to perform actions against this XXXX source."

 

Is there a way to send a GET request while keeping the "-d" part of it?

6 Replies

  • rainer1's avatar
    rainer1
    Resolver III

    Hi fdanielsouza ,

     

    let
    	content = "{
    		""method"": ""get"",
    		   ""params"": {
    		      ""SelectionCriteria"": {},
    		      ""FieldNames"": [""Id"", ""Name""]
    		   }
    	}",
    
    	Source = Json.Document(Web.Contents("https://api.salaovip.com.br/reports/0005?page=1&limit=100", [Headers=[Authorization="Bearer AQAAAAANlKwBAAQQn4Wfgbxxxxxxxxxx"], Content=Text.ToBinary(content)]))
    in
        Source

     

    try these code above with adjusted parameter Bearer etc. it should work

     

    -------------------------------------------------------------------
    Did I answer your question? Mark my post as a solution!
    It was useful? Press Thumbs Up! 

    • fdanielsouza's avatar
      fdanielsouza
      Helper I

      rainer1 , thank you for the help and sorry I'm replying late, please look if this is what you meant me to do, because it still raises the 405 status error

       

       

       

      • artemus's avatar
        artemus
        Microsoft Employee

        Have you tried manual status handling? E.g.:

        = Value.Metadata(Web.Contents("https://example.com", [ManualStatusHandling={405}, Content=Text.ToBinary("<Content>")]))[Content.Uri]()