MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    How to pass extra variable to a Https Get Request

    Scheduled Pinned Locked Moved Development
    1 Posts 1 Posters 970 Views 1 Watching
    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.
    • P Offline
      prysme01
      last edited by

      Hello everyone,

      I’m pretty new to NodeJS, but I’m working on a module for the Home automation JEEDOM.
      I’m stuck at being able to do a simple GET and having the context during async GET response in order to know from where my request came from

      var req = https.get("https://JEEDOMURL/core/api/jeeApi.php?apikey=...&type=cmd&id=127");
      req.idx = "127";
      req.on("response", function(res){
      	res.on('data', (d) => {		
      	console.log("DEBUG : " + req.idx +" / "+ typeof (d));
      	console.log("DEBUG : " + req.idx +" / "+ d);
      	})
      });
      
      var req = https.get("https://JEEDOMURL/core/api/jeeApi.php?apikey=...&type=cmd&id=695");
      req.idx = "695";
      req.on("response", function(res){
      	res.on('data', (d) => {		
      	console.log("DEBUG : " + req.idx +" / "+ typeof (d));
      	console.log("DEBUG : " + req.idx +" / "+ d);
      	})
      });
      

      With no surprise I’m getting
      DEBUG : 695 / object
      DEBUG : 695 / 5515
      DEBUG : 695 / object
      DEBUG : 695 / 19.8

      instead of getting
      DEBUG : 695 / object
      DEBUG : 127 / 5515
      DEBUG : 695 / object
      DEBUG : 695 / 19.8

      I know that is expected by JS async guru, but How can I explicitly pass a variable and getting my http get DATA synchronize.

      I’ve read a lot of module code, and unfortunately for me JEEDOM is not giving me any context information in the GET answer
      https://JEEDOMURL/core/api/jeeApi.php?apikey=...&type=cmd&id=127" is only responding 5515
      and https://JEEDOMURL/core/api/jeeApi.php?apikey=...&type=cmd&id=695" is responding 19.8

      Any help would be appreciate ?

      Thanks in advance for your time.
      I’m really stuck, and I don’t want to parse the URL to get back my ID.

      1 Reply Last reply Reply Quote 0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • 1 / 1
      • First post
        Last post
      Enjoying MagicMirror? Please consider a donation!
      MagicMirror created by Michael Teeuw.
      Forum managed by Sam, technical setup by Karsten.
      This forum is using NodeBB as its core | Contributors
      Contact | Privacy Policy