makeWebRequest in WF

Hi to all.

Trying to add Tide data to my WF (from www.worldtides.info).
Is there some good manuals, how to make it?

I've tried to act as described in API manual, but it's complaining that "Permission Required", however, I opened permission for "Background" and "Communication" in manifest.
Developer's guide sad nothing about WF possibility for Communication, only for widgets and App, but, as I so, developers add somehow weather forecasts from internet into WF.
Means that I’m again doing something wrong.


here part of code, just to clear the idea:

function onReceieve(responseCode, data) {
if (responseCode == 200) {
System.println("Request Successful"); // print success
}
else {
System.println("Response: " + responseCode); // print response code
}
}

function makeRequest() {
var url = "www.worldtides.info/api // set the url

var params = { // set the parameters
"extremes" => "extremes",
"lat" => "47,095140",
"lon" => "37,541310",
"key" => "47cde680-420a-41eb-b278-c37ddcaxxxxx"
};

var options = { // set the options
:method => Communications.HTTP_REQUEST_METHOD_GET, // set HTTP method
:headers => { // set headers
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
// set response type
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
};

var responseCallback = method(:onReceive); // set responseCallback to
// onReceive() method
// Make the Communications.makeWebRequest() call
Communications.makeWebRequest(url, params, options, method(:onReceive));
}

  • To get the information to display on a watch face, you need to make use of the background services. Jim_m_58 has a nice blog write up with an example.

    https://developer.garmin.com/index.php/blog/post/guest-post-creating-a-connect-iq-background-service

  • Thanks, will read.
    Already preview next headache - i have one BG process in WF on hourly basics. Now will try to combinate with Tidal, on 48hr basics...
  • Not so much in a link.

    I've tried to make widget first, for testing. And again, in dead-end...
    Widget sending call to web, on web-page, counter calculation this call (means, call - successful),
    but on response - coming: “responseCode” = 400 (must be 200) and “data” = null. Should be in default JSON.

    Could someone point what I’m doing wrong, please?

    Here basic code below:

    First try from API manual:
    function makeRequest() {
    var url = "www.worldtides.info/api

    var params = {}; //Here i tried to insert parametrs - same story...
    var options = {};
    var responseCallback = method(:onReceive);
    Communications.makeWebRequest(url, params, options, method(:onReceive));

    }
    function onReceive(responseCode, data) {
    Sys.println(responseCode);
    Sys.println(data);
    if (responseCode == 200) {
    Sys.println("We are Connected!!!");
    } else {
    Sys.println("Againg not working...");
    }
    }


    Other from SDK sample:
    function makeRequest() {

    Comm.makeWebRequest(
    "www.worldtides.info/api
    {},{},
    method(:onReceive)
    );
    }
    function onReceive(responseCode, data) {
    Sys.println(responseCode);
    Sys.println(data);
    if (responseCode == 200) {
    Sys.println("We are Connected!!!");
    } else {
    Sys.println("Againg not working...");
    }
    }
  • Get connection by adding option:
    var options = {:responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON};