Acknowledged
over 1 year ago

Unable of using makeWebRequest function

Hello, I'm using Connect IQ 7.2.1 and I'm facing some issues with the makeWebRequest function when using Venu3S as device.

I'm using the official documentation (https://developer.garmin.com/connect-iq/api-docs/Toybox/Communications.html) with this code:

    using Toybox.System;
   using Toybox.Communications;

       function onReceive(responseCode, data) {
           if (responseCode == 200) {
               System.println("Request Successful");
           }
           else {
               System.println("Response: " + responseCode);
           };
       };

       function makeRequest() {
           var url = "https://www.garmin.com";     

           var params = {                                      
                  "definedParams" => "123456789abcdefg"
           };

           var options = {
               :method => Communications.HTTP_REQUEST_METHOD_GET,  
               :headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
               :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_URL_ENCODED
           };

           var responseCallback = method(:onReceive);                  
           Communications.makeWebRequest(url, params, options, responseCallback);
      }
      
However, I do receive this error which I do not know how to solve:  
  venu3s: Invalid '$.Toybox.Lang.Method(responseCode as Any, data as Any) as Any' passed as parameter 4 of type 'PolyType<($.Toybox.Lang.Method(responseCode as $.Toybox.Lang.Number, data as Null or $.Toybox.Lang.Dictionary or $.Toybox.Lang.String or $.Toybox.PersistedContent.Iterator) as Void) or ($.Toybox.Lang.Method(responseCode as $.Toybox.Lang.Number, data as Null or $.Toybox.Lang.Dictionary or $.Toybox.Lang.String or $.Toybox.PersistedContent.Iterator, context as $.Toybox.Lang.Object) as Void)>'.

I'd really appreciate some support on this topic.

Parents
  • This is something I would normally recommend posting about in the discussion forums since this is not proven to be a bug yet, and may simply be a coding error (though this appears to be the sample code from our documentation). I do immediately see a problem in the code—there is a missing ';' at the end of the line for the "definedParams" dictionary, though I'm not certain that's the cause of the error you're seeing. Do you also receive this error within the simulator, and if so, does it occur with any device profile, or only while running as Venu 3S?

Comment
  • This is something I would normally recommend posting about in the discussion forums since this is not proven to be a bug yet, and may simply be a coding error (though this appears to be the sample code from our documentation). I do immediately see a problem in the code—there is a missing ';' at the end of the line for the "definedParams" dictionary, though I'm not certain that's the cause of the error you're seeing. Do you also receive this error within the simulator, and if so, does it occur with any device profile, or only while running as Venu 3S?

Children