Announcement

Collapse
No announcement yet.

Error on makeWebRequest returned data

Collapse
X
  • Time
  • Show
Clear All
new posts

  • Error on makeWebRequest returned data

    I'm experiencing an error (Failed invoking <symbol>) after a return from makeWebRequest. Is suspect it may be a data typing, but it has me stumped.

    Here is the code:

    Code:
        function onReceive(responseCode, data) {
            if (responseCode == 200) {
                System.println("Request Successful");                   // print success
    
    //****** The following println throws "Failed invoking <symbol>"
    
                System.println("bg exit: " + data); 
                System.println("Exiting background");        
                Background.exit(data);
            } else {
                System.println("Response: " + responseCode);            // print response code
            }
        }
    
        function onTemporalEvent() {
    
            Communications.makeWebRequest(
                "https://api.darksky.net/forecast/<secret_key>/37.8267,-122.4233",
                { "exclude" => "[hourly,currently,daily,alerts,flags]"
                },
                {
                    :headers => { "Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED
                        },
                        :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
                },
                method(:onReceive)
    
            );
        }
    The line

    Code:
                System.println("bg exit: " + data);
    in the onReceive method throws the "Failed invoking <symbol>" error. The return from the server is JSON.

    However, the following code (which is from the ConnectIQ WebRequest example and which also returns JSON) works:

    Code:
        function makeRequest() {
            notify.invoke("Executing\nRequest");
            Comm.makeWebRequest(
                "https://jsonplaceholder.typicode.com/todos/115",
                {
                },
                {
                    "Content-Type" => Comm.REQUEST_CONTENT_TYPE_URL_ENCODED
                },
                method(:onReceive)
            );
        }
    I'm quite certain this is a blind noob problem, but appreciate any help!

  • #2
    I thought it might be useful to show the JSON from the two calls:

    From the broken darksky call:

    Code:
     {"latitude":37.8267,"longitude":-122.4233,"timezone":"America/Los_Angeles","minutely":{"summary":"Clear for the hour.","icon":"clear-day","data":[{"time":1523576100,"precipIntensity":0,"precipProbability":0},{"time":1523576160,"precipIntensity":0,"precipProbability":0},{"time":1523576220,"precipIntensity":0,"precipProbability":0},{"time":1523576280,"precipIntensity":0,"precipProbability":0},{"time":1523576340,"precipIntensity":0,"precipProbability":0},{"time":1523576400,"precipIntensity":0,"precipProbability":0},{"time":1523576460,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.01,"precipType":"rain"},{"time":1523576520,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.01,"precipType":"rain"},{"time":1523576580,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.02,"precipType":"rain"},{"time":1523576640,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.03,"precipType":"rain"},{"time":1523576700,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.04,"precipType":"rain"},{"time":1523576760,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.05,"precipType":"rain"},{"time":1523576820,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.07,"precipType":"rain"},{"time":1523576880,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.08,"precipType":"rain"},{"time":1523576940,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.09,"precipType":"rain"},{"time":1523577000,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.1,"precipType":"rain"},{"time":1523577060,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.11,"precipType":"rain"},{"time":1523577120,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.12,"precipType":"rain"},{"time":1523577180,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.13,"precipType":"rain"},{"time":1523577240,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.14,"precipType":"rain"},{"time":1523577300,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.14,"precipType":"rain"},{"time":1523577360,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.14,"precipType":"rain"},{"time":1523577420,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.15,"precipType":"rain"},{"time":1523577480,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.15,"precipType":"rain"},{"time":1523577540,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.15,"precipType":"rain"},{"time":1523577600,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.15,"precipType":"rain"},{"time":1523577660,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.14,"precipType":"rain"},{"time":1523577720,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.14,"precipType":"rain"},{"time":1523577780,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.15,"precipType":"rain"},{"time":1523577840,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.15,"precipType":"rain"},{"time":1523577900,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.14,"precipType":"rain"},{"time":1523577960,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.14,"precipType":"rain"},{"time":1523578020,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.14,"precipType":"rain"},{"time":1523578080,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.14,"precipType":"rain"},{"time":1523578140,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.14,"precipType":"rain"},{"time":1523578200,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.14,"precipType":"rain"},{"time":1523578260,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.13,"precipType":"rain"},{"time":1523578320,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.13,"precipType":"rain"},{"time":1523578380,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.13,"precipType":"rain"},{"time":1523578440,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.13,"precipType":"rain"},{"time":1523578500,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.12,"precipType":"rain"},{"time":1523578560,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.12,"precipType":"rain"},{"time":1523578620,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.12,"precipType":"rain"},{"time":1523578680,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.11,"precipType":"rain"},{"time":1523578740,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.12,"precipType":"rain"},{"time":1523578800,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.11,"precipType":"rain"},{"time":1523578860,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.11,"precipType":"rain"},{"time":1523578920,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.11,"precipType":"rain"},{"time":1523578980,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.11,"precipType":"rain"},{"time":1523579040,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.1,"precipType":"rain"},{"time":1523579100,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.1,"precipType":"rain"},{"time":1523579160,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.1,"precipType":"rain"},{"time":1523579220,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.1,"precipType":"rain"},{"time":1523579280,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.1,"precipType":"rain"},{"time":1523579340,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.09,"precipType":"rain"},{"time":1523579400,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.09,"precipType":"rain"},{"time":1523579460,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.09,"precipType":"rain"},{"time":1523579520,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.09,"precipType":"rain"},{"time":1523579580,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.09,"precipType":"rain"},{"time":1523579640,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.08,"precipType":"rain"},{"time":1523579700,"precipIntensity":0.003,"precipIntensityError":0.001,"precipProbability":0.08,"precipType":"rain"}]},"offset":-7}


    From the working example call:
    Code:
    {   "userId": 6,   "id": 115,   "title": "sed et ea eum",   "completed": false }
    Last edited by onmyfeetoutside; 04-12-2018, 05:40 PM. Reason: Added clarification on working/not working.

    Comment


    • #3
      This really should be posted in the Connect IQ Developer's Forum. This one if for things other than CIQ. I've used dark sky in the background and nothing jumps out though.
      Last edited by jim_m_58; 04-12-2018, 06:35 PM.
      My Connect IQ Apps in the Store
      Facebook - Instagram -
      Twitter

      Comment


      • #4
        Thanks, Jim. Will do.

        Comment

        Working...
        X