Windy Community

    • Register
    • Login
    • Search
    • Unread
    • Categories
    • Groups
    • Go to windy.com

    Javascript fetch

    Developers
    3
    5
    1382
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Marcelklim last edited by marekd

      I am trying to fetch the windy data, but get an error;
      Unexpected token W in JSON at position 0
      at /node_modules/node-fetch/lib/body.js:48:31
      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
      name: 'FetchError',
      message: 'invalid json response body at https://api.windy.com/api/point-forecast/v2 reason: Unexpected token W in JSON at position 0',
      type: 'invalid-json'

      What could be the problem in my script?

      let _data = { 
      "lat": 52.046,
      "lon": 4.447,
      "model": "iconeu",
      "parameters": ["wind"],
      "levels": ["surface"],
      "key": "..."};
      

      fetch("https://api.windy.com/api/point-forecast/v2", {
      method: 'POST',
      body: _data,
      headers: {"Content-type": "application/json; charset=UTF-8"}
      })
      .then(response => response.json())
      .then(Server => {
      console.log(Server) // Prints result from response.json()
      // var UvNow = Server.result.uv;//Processing UVToday
      // BLApp.apiPut("UvNow/"+UvNow);//Updating better logic variable UVToday
      })
      .catch(error => console.error(error))
      // OpenUvServer = false
      // var StandardProcessing = false
      // console.log("i is: " +i)

      1 Reply Last reply Reply Quote 0
      • vicb
        vicb Paraglider | Premium last edited by

        You should look at the windy repository with plugin examples.

        Check this plugin.

        1 Reply Last reply Reply Quote 0
        • marekd
          marekd Administrator last edited by marekd

          Also, you should not publish your key for Point Forecast API. I removed it from your post. Unlike from eg. Map Forecast, Point Forecast is a server-2-server servise and it is not possible to secure your key against missusing.

          M 1 Reply Last reply Reply Quote 0
          • M
            Marcelklim @marekd last edited by

            @marekd

            thx, but i changed the key efore posting avoiding abuse of my key. at this moment i still can't get the fetch done. the plugin is webbased? I try to get it done with javascript on a computer

            1 Reply Last reply Reply Quote 0
            • vicb
              vicb Paraglider | Premium last edited by

              @Marcelklim said in Javascript fetch:

              fetch("https://api.windy.com/api/point-forecast/v2", {
              method: 'POST',
              body: _data,
              headers: {"Content-type": "application/json; charset=UTF-8"}
              })

              You should try body: JSON.stringify(_data)

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Windyty, S.E. - all rights reserved. Powered by excellent NodeBB
              NodeBB & contributors, OSM & contributors, HERE maps
              Terms and Conditions     Privacy Policy