makeWebRequest Microsoft Flow - 401

Hi guys,

I've created some ?C devices, which transfer some data to a Microsoft Flow. (Arduino based ESP8266 WiFi modules)
That works great, so I got in mind also to do that with my gamin :)

Flow gives you a https-URL with a connection string included:
URL
Transport-method is POST
Data is a simple Json.

My attempt was to reuse the code from the API. It contains a lot or typos, missing chars and does not compile
This is quite similar to my C code on my microcontroller. But I receive a 401 all the time!
I tried some different approaches, but they gave me negative status codes, so I think I made it worse.

function makeRequest()
{

}


To ensure the way to submit the data is fine, I created several requests with https://www.hurl.it/.
Post, no authentication, Header = Content Type and my values as parameter. This also work fine!

The Emulator is set to "Use Device Https Requirements" and is running on the same machine, on the same network, where my microcontrollers are.

  • Due to this fantastic Forum software, I cannot even Edit and preview the previous post :mad:

    The URL looks like that:
    prod-45.westeurope.logic.azure.com:443/.../invoke & sig=AbCdEfGhIjKlMnOpQrStUvW1234567890


    function makeRequest()
    {
    var url = "see previous Post";
    var params =
    {
    "device" => "ESP8266MOD",
    "no" => "19",
    "ipAdress" => "192.168.100.19",
    "epoch" => "1500990912"
    };

    var options =
    {
    :methods => Comm.HTTP_REQUEST_METHOD_POST,
    :headers =>
    {
    "Content-Type" => Comm.REQUEST_CONTENT_TYPE_JSON
    },
    :responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
    };
    var responseCallback = method( : onReceive);
    Communications.makeWebRequest(url, params, options, responseCallback);
    }


    EDIT:
    Still receiving 401, whatever I change.
    To get further, I tried to export the App to my device, but "Build for Device Wizard" is not starting. Onclicked it several times, but nothing happens. Still after some restarts...
    "App Export Wizard" -> Upload it as a Beta app and installed it!

    Now I receive a -300 (NETWORK_REQUEST_TIMED_OUT) after about a second. Tried it with Connect Mobile running/in background, display on/off, WiFi/LTE, still a -300.
  • Can you link to the documentation for the HTTP/HTTPS endpoint for use with Flow? I can't seem to find what I'd need to verify you're building the request correctly.
  • Hi Travis,
    I didn't found it either. Currently MS is developing and releasing faster then documenting their stuff...
    But here is a tutorial, to get an insight.

    As far as I can see it from https://www.hurl.it/ or Postman, the request insists on four parts:
    • URL
    • Header
    • Body
    • Query

    It separates the URL from authentication-token, version, api and sp. They where put into the query (Whatever that is and how it is submitted).
    Maybe that is a problem, that the url already contains the question mark and ampersands to submit these query data. I expect garmin to attach the parameter with ?param1=1&param2=2...
    That won?t work, if there is already a question mark.

    My latest attempt gave me a 400:
    var url = "prod-45.westeurope.logic.azure.com/.../invoke";
    var params =

    {
    "device" => "ESP8266MOD",
    "no" => "19",
    "ipAdress" => "192.168.100.19",
    "epoch" => "1500990912"
    };

    var options =
    {
    :methods => Comm.HTTP_REQUEST_METHOD_POST,
    :headers =>
    {
    "Content-Type" => Comm.REQUEST_CONTENT_TYPE_JSON,
    "sig" => "bCdEfGhIjKlMnOpQrStUvW1234567890",
    "sp" => "/triggers/manual/run",
    "api-version" => "2016-06-01",
    "sv" => "1.0"
    },
    :responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
    };
    var responseCallback = method( : onReceive);
    Communications.makeWebRequest(url, params, options, responseCallback);

    Seems not to be the solution.

    If you'd like, I'll send you a PM with my credentials :)
  • Update:
    I've created an Azure Function without Authentication-Key. Changed the URL and it worked from then on!
    Its just a cloud hosted webservice, which can be developed online. The json-request will be routed into my Flow (with authentication.key), which accept it with a 202.
    The Result will create a 0 - Unknown Error.
    If the result is manually overwritten with status 200 OK and some random body like {"Message":"Sucessful"} I receive a -400 invalid Http Body.
    EDIT: Found my issue on this one. Using request.CreateResponse() does not take the contentType into the response. It has to be set manually!

    Both work on Flow side :)

    Three things leave open to me:
    • A 202 response should be accepted successfully -> Solved
    • The key should work inside a url (right now the access totally unsecured)
    • What do I have to respond, to get a 200 state? -> Solved

    Point 2 is still open for me. I created an issue here.