Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JavaScript
  5. Plötzlich ReferenceError: request is not defined

NEWS

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    8.6k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    13
    1
    2.1k

  • Neues Video "KI im Smart Home" - ioBroker plus n8n
    BluefoxB
    Bluefox
    16
    1
    2.8k

Plötzlich ReferenceError: request is not defined

Geplant Angeheftet Gesperrt Verschoben JavaScript
75 Beiträge 9 Kommentatoren 11.1k Aufrufe 8 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • X XWing

    @haus-automatisierung said in Plötzlich ReferenceError: request is not defined:

    response.data.split('\n');

    Juhu! Es geht endlich!
    Falls es noch einmal jemand brauchen sollte (Auslesen der Werte aus einem Senertec Dachs BHKW) hier das funktionierende Script:

    
    const url = 'http://glt:Passwort@IP des BHKW:8080/getKey?k=Hka_Mw1.Temp.sbAussen&k=Hka_Bd.ulArbeitThermHka&k=Hka_Bd.ulArbeitElektr&k=Hka_Bd.ulBetriebssekunden&k=Hka_Mw1.Temp.sbRuecklauf&k=Hka_Mw1.Temp.sbVorlauf&k=Wartung_Cache.fStehtAn&k=Hka_Mw1.Temp.sbFuehler1&k=Hka_Mw1.usDrehzahl&k=Hka_Mw1.Aktor.fUPKuehlung&k=Hka_Bd_Stat.uchSeriennummer&k=Hka_Bd_Stat.uchTeilenummer&k=Hka_Bd_Stat.ulInbetriebnahmedatum&k=Wartung_Cache.ulBetriebssekundenBei&k=Wartung_Cache.ulZeitstempel&k=Wartung_Cache.usIntervall&k=Hka_Mw1.ulMotorlaufsekunden&k=Hka_Mw1.Aktor.fStoerung&k=Hka_Mw1.Aktor.fWartung&k=Hka_Mw1.Aktor.fUPVordruck&k=Hka_Mw1.sWirkleistung&k=Hka_Mw1.Temp.sAbgasHKA&k=Hka_Mw1.Temp.sAbgasMotor&k=Hka_Mw1.Temp.sKapsel&k=Hka_Mw1.Temp.sbFreigabeModul&k=Hka_Mw1.Temp.sbGen&k=Hka_Mw1.Temp.sbMotor&k=Hka_Mw1.Temp.sbRegler&k=Hka_Mw1.Solltemp.sbRuecklauf&k=Hka_Mw1.Solltemp.sbVorlauf&k=Hka_Bd.ulAnzahlStarts&k=Hka_Bd.ulArbeitElektr&k=Hka_Bd.ulArbeitThermHka&k=Hka_Bd.ulArbeitThermKon&k=BD3112.Hka_Bd.ulBetriebssekunden&k=BD3112.Hka_Bd.ulAnzahlStarts&k=BD3112.Hka_Bd.ulArbeitElektr&k=BD3112.Hka_Bd.ulArbeitThermHka&k=BD3112.Hka_Bd.ulArbeitThermKon&k=Hka_Bd.bStoerung&k=Hka_Bd.bWarnung';
    const idPath = '0_userdata.0.BHKW.';
     
    const idRLT = idPath + 'RL-Temperatur';
     
    const idBetrieb = idPath + 'Betriebsstunden';
     
    const idAT = idPath + 'Aussen-Temperatur';
     
    const idATh = idPath + 'Heizkreis-Energie';
     
    const idAEl = idPath + 'Elektroenergie';
     
    const idVLT = idPath + "VL-Temperatur";
    const idTF1 = idPath + "Temperatur_Fuehler_1";
    const idDZ = idPath + "Motordrehzahl";
    const idWN = idPath + "Wartung-notwendig";
    const idST = idPath + "Stoerung";
    const idWR = idPath + "Wartungsrelais";
    const idAKK = idPath + "Interne_Umwaelzpumpe";
    const idSNR = idPath + "Seriennummer";
    const idTNR = idPath + "Teilenummer";
    const idINB = idPath + "Inbetriebnahmedatum";
    const idWLZT = idPath + "Letzte_Wartung";
    const idWAM = idPath + "LWartung_am";
    const idWINT = idPath + "Wartungsinterval";
    const idALZ = idPath + "Motorlaufzeit-Start";
    const idUPV = idPath + "UP_Vordruck";
    const idWLST = idPath + "A_Wirkleistung";
    const idWAIN = idPath + "Wartung_in_h";
    const idTDA = idPath + "Abgastemp_Dachs";
    const idTMO = idPath + "Abgastemp_Motor";
    const idTKA = idPath + "Kapseltemperatur";
    const idTFR = idPath + "Freigabemodul";
    const idTEIN = idPath + "Dachs-Eintrittstemperatur";
    const idTKM = idPath + "Kuehlwasser-Motor";
    const idTIR = idPath + "Interne_Reglertemperatur";
    const idSOR = idPath + "Solltemperatur_Ruecklauf";
    const idSOV = idPath + "Solltemperatur_Vorlauf";
    const idSTAR = idPath + "Anzahl-Starts";
    const idSEL = idPath + "Erzeugte_elektrische_Arbeit";
    const idSWEN = idPath + "Erzeugte_thermische_Arbeit";
    const idSWEK = idPath + "Erzeugte_thermische_Arbeit_Kondenser";
    const idSEL31 = idPath + "Erzeugte_elektrische_Arbeit_31_12";
    const idSWEN31 = idPath + "Erzeugte_thermische_Arbeit_31_12";
    const idSWEK31 = idPath + "Erzeugte_thermische_Arbeit_Kondenser_31_12";
    const idSTAR31 = idPath + "Anzahl-Starts_31_12";
    const idBetrieb31 = idPath + 'Betriebsstunden_31_12';
    const idSTNR = idPath + 'Aktuelle_Stoerung_Nr';
    const idWARN = idPath + 'Aktueller_Warncode';
    const altzeit = idPath + 'Betriebsstunden-alt'
      
    function getBHKW() {
        httpGet(url, { timeout: 2000, responseType: 'text' }, async (err, response) => {
            if (err) {
                console.error(err);
            } else {
                    const arr = response.data.split('\n');;
                    
                for (let i = 0; i < arr.length; i++) {
                    let sensor = arr[i].split('=');
                     if (sensor[0].indexOf('Temp.sbRuecklauf') != -1) setState(idRLT, parseFloat(sensor[1]), true);
     
                    if (sensor[0].indexOf('ulBetriebssekunden') != -1) setState(altzeit,parseFloat(sensor[1]), true ); // Stunden mit 2 Nachkommastellen
                    if (getState(idBetrieb).val<getState(altzeit).val) setState(idBetrieb, getState(altzeit).val, true); //nur höhere Werte loggen
                    if (sensor[0].indexOf('sbAussen') != -1) setState(idAT, parseFloat(sensor[1]), true);
     
                    if (sensor[0].indexOf('ulArbeitThermHka') != -1) setState(idATh, parseFloat(sensor[1]), true);
     
                    if (sensor[0].indexOf('ulArbeitElektr') != -1) setState(idAEl, parseFloat(sensor[1]), true);
     
                    if (sensor[0].indexOf('Temp.sbVorlauf') != -1) setState(idVLT, parseFloat(sensor[1]), true);
     
                    if (sensor[0].indexOf('sbFuehler1') != -1) setState(idTF1, parseFloat(sensor[1]), true);
     
                    if (sensor[0].indexOf('usDrehzahl') != -1) setState(idDZ, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('uchSeriennummer') != -1) setState(idSNR, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('uchTeilenummer') != -1) setState(idTNR, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('ulInbetriebnahmedatum') != -1) setState(idINB, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('ulBetriebssekundenBei') != -1) setState(idWLZT, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('ulAnzahlStarts') != -1) setState(idSTAR, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('ulZeitstempel') != -1) setState(idWAM, Math.round(parseFloat(sensor[1])), true);
                    if (sensor[0].indexOf('usIntervall') != -1) setState(idWINT, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('ulMotorlaufsekunden') != -1) setState(idALZ, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('sWirkleistung') != -1) setState(idWLST, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('sAbgasHKA') != -1) setState(idTDA, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('sAbgasMotor') != -1) setState(idTMO, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('sKapsel') != -1) setState(idTKA, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('sbFreigabeModul') != -1) setState(idTFR, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('sbGen') != -1) setState(idTEIN, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('sbMotor') != -1) setState(idTKM, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('sbRegler') != -1) setState(idTIR, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('Solltemp.sbRuecklauf') != -1) setState(idSOR, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('Solltemp.sbVorlauf') != -1) setState(idSOV, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('Hka_Bd.ulArbeitElektr') != -1) setState(idSEL, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('Hka_Bd.ulArbeitThermHka') != -1) setState(idSWEN, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('Hka_Bd.ulArbeitThermKon') != -1) setState(idSWEK, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('BD3112.Hka_Bd.ulArbeitElektr') != -1) setState(idSEL31, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('BD3112.Hka_Bd.ulArbeitThermHka') != -1) setState(idSWEN31, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('BD3112.Hka_Bd.ulArbeitThermKon') != -1) setState(idSWEK31, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('BD3112.Hka_Bd.ulAnzahlStarts') != -1) setState(idSTAR31, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('BD3112.Hka_Bd.ulBetriebssekunden') != -1) setState(idBetrieb31, parseFloat(sensor[1]), true);
                    if (sensor[0].indexOf('Hka_Bd.bStoerung') != -1) setState(idSTNR, parseFloat(sensor[1])+100, true);
                    if (sensor[0].indexOf('Hka_Bd.bWarnung') != -1) setState(idWARN, parseFloat(sensor[1])+600, true);
     
                    if (sensor[0].indexOf('fStehtAn') != -1) setState(idWN, toBoolean(sensor[1]), true); 
     
                    if (sensor[0].indexOf('fUPKuehlung') != -1) setState(idAKK, toBoolean(sensor[1]), true); 
                    if (sensor[0].indexOf('fStoerung') != -1) setState(idST, toBoolean(sensor[1]), true); 
                    if (sensor[0].indexOf('fWartung') != -1) setState(idWR, toBoolean(sensor[1]), true); 
                    if (sensor[0].indexOf('fUPVordruck') != -1) setState(idUPV, toBoolean(sensor[1]), true); 
                }
            }
        });
    }
     
    getBHKW(); // Script start
    schedule('* * * * *', getBHKW); // jede Minute
    
    

    Danke an alle!

    K Offline
    K Offline
    kptkip
    schrieb am zuletzt editiert von
    #39

    Würde mich gerne mal hier dran hängen, da ich ebenfalls ein Script im Einsatz habe, das mit request daher kommt.

    Allerdings nutzt es nicht GET sondern POST als Methode. Ein stumpfes Ersetzen von httpGet nach httpPost hat nicht geklappt. Dann hagelte es jede Menge Fehler...

    Das besagte Snippet sieht so aus:

    request.post({
          url: uri,
          headers: {
            'Authorization': 'Bearer ' + Token
          }
        }, function(error, response, body) {
          if (error) {
            console.error(error);
            
          } else {
            //console.log(body);
            output = body;
            setState("0_userdata.0.Polestar.Tibber_Response", output);
            
          }
        });
    
    T 1 Antwort Letzte Antwort
    0
    • K kptkip

      Würde mich gerne mal hier dran hängen, da ich ebenfalls ein Script im Einsatz habe, das mit request daher kommt.

      Allerdings nutzt es nicht GET sondern POST als Methode. Ein stumpfes Ersetzen von httpGet nach httpPost hat nicht geklappt. Dann hagelte es jede Menge Fehler...

      Das besagte Snippet sieht so aus:

      request.post({
            url: uri,
            headers: {
              'Authorization': 'Bearer ' + Token
            }
          }, function(error, response, body) {
            if (error) {
              console.error(error);
              
            } else {
              //console.log(body);
              output = body;
              setState("0_userdata.0.Polestar.Tibber_Response", output);
              
            }
          });
      
      T Offline
      T Offline
      TT-Tom
      schrieb am zuletzt editiert von TT-Tom
      #40

      @kptkip sagte in Plötzlich ReferenceError: request is not defined:

      Versuch mal das

      
      httpPost(uri, {headers: {
              'Authorization': 'Bearer ' + Token
            } }, (error, response) => {
         if (!error) {
             console.log(response.statusCode);
             console.log(response.data);
             console.log(response.headers);
              output = response.data;      
        setState("0_userdata.0.Polestar.Tibber_Response", output);
              
            } else { 
               console.log(error) }
          });
      

      Gruß Tom
      https://github.com/tt-tom17
      Wenn meine Hilfe erfolgreich war, benutze bitte das Voting unten rechts im Beitrag

      NSPanel Script Wiki
      https://github.com/joBr99/nspanel-lovelace-ui/wiki

      NSPanel Adapter Wiki
      https://github.com/ticaki/ioBroker.nspanel-lovelace-ui/wiki

      K 1 Antwort Letzte Antwort
      0
      • T TT-Tom

        @kptkip sagte in Plötzlich ReferenceError: request is not defined:

        Versuch mal das

        
        httpPost(uri, {headers: {
                'Authorization': 'Bearer ' + Token
              } }, (error, response) => {
           if (!error) {
               console.log(response.statusCode);
               console.log(response.data);
               console.log(response.headers);
                output = response.data;      
          setState("0_userdata.0.Polestar.Tibber_Response", output);
                
              } else { 
                 console.log(error) }
            });
        
        K Offline
        K Offline
        kptkip
        schrieb am zuletzt editiert von
        #41

        @TT-Tom

        Cool, das geht definitv in die richtige Richtung. Allerdings findet die tibber-API (die zapfe ich nämlich an) da etwas nicht in Ordnung:

        {
          "errors": [
            {
              "message": "GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension.",
              "extensions": {
                "code": "INTERNAL_SERVER_ERROR",
                "exception": {
                  "stacktrace": [
                    "GraphQLError: GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension.",
                    " at processGraphQLRequest (/app/node_modules/apollo-server-core/dist/requestPipeline.js:73:40)",
                    " at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
                    " at async processHTTPRequest (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:222:30)"
                  ]
                }
              }
            }
          ]
        }
        

        Ich kopier mal das Originalscript (mit Workaround) in voller Länge hier rein, vlt. wird die Erwartung der API deutlicher:

        const request = require('request');
        
        //Get Token from Tibber
        var LoginUri = "https://app.tibber.com/login.credentials";
        var output = "1";
        var params = {
          "@type": "login",
          "email": [EMAIL],
          'password': [PASSWD]};
        
        //Using the request.post function to send a POST request with JSON data
        request.post({
          url: LoginUri,
          json: params
        }, function(error, response, body) {
          if (error) {
            console.error(error);
          } else {
            var TokenFromLogin = body.token;
            //console.log(TokenFromLogin);
        
            //Request Battery Status
            var uri = "https://app.tibber.com/v4/gql?query={me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}";
            var Token = TokenFromLogin;
            //Using the request.post function to send a POST request with a Bearer token
              request.post({
                  url: uri,
                  headers: {
                      'Authorization': 'Bearer ' + Token
                  }
              }, function (error, response, body) {
                  if (error) {
                      console.error(error);
        
                  } else {
                      //console.log(body);
                      output = body;
                      setState("0_userdata.0.Polestar.Tibber_Response", output);
        
                  }
              });
          }
        });
        
        T 2 Antworten Letzte Antwort
        0
        • K kptkip

          @TT-Tom

          Cool, das geht definitv in die richtige Richtung. Allerdings findet die tibber-API (die zapfe ich nämlich an) da etwas nicht in Ordnung:

          {
            "errors": [
              {
                "message": "GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension.",
                "extensions": {
                  "code": "INTERNAL_SERVER_ERROR",
                  "exception": {
                    "stacktrace": [
                      "GraphQLError: GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension.",
                      " at processGraphQLRequest (/app/node_modules/apollo-server-core/dist/requestPipeline.js:73:40)",
                      " at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
                      " at async processHTTPRequest (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:222:30)"
                    ]
                  }
                }
              }
            ]
          }
          

          Ich kopier mal das Originalscript (mit Workaround) in voller Länge hier rein, vlt. wird die Erwartung der API deutlicher:

          const request = require('request');
          
          //Get Token from Tibber
          var LoginUri = "https://app.tibber.com/login.credentials";
          var output = "1";
          var params = {
            "@type": "login",
            "email": [EMAIL],
            'password': [PASSWD]};
          
          //Using the request.post function to send a POST request with JSON data
          request.post({
            url: LoginUri,
            json: params
          }, function(error, response, body) {
            if (error) {
              console.error(error);
            } else {
              var TokenFromLogin = body.token;
              //console.log(TokenFromLogin);
          
              //Request Battery Status
              var uri = "https://app.tibber.com/v4/gql?query={me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}";
              var Token = TokenFromLogin;
              //Using the request.post function to send a POST request with a Bearer token
                request.post({
                    url: uri,
                    headers: {
                        'Authorization': 'Bearer ' + Token
                    }
                }, function (error, response, body) {
                    if (error) {
                        console.error(error);
          
                    } else {
                        //console.log(body);
                        output = body;
                        setState("0_userdata.0.Polestar.Tibber_Response", output);
          
                    }
                });
            }
          });
          
          T Offline
          T Offline
          TT-Tom
          schrieb am zuletzt editiert von
          #42

          @kptkip
          Wenn jetzt kein anderer User schneller ist, sehe ich mir das heute Abend an.

          Gruß Tom
          https://github.com/tt-tom17
          Wenn meine Hilfe erfolgreich war, benutze bitte das Voting unten rechts im Beitrag

          NSPanel Script Wiki
          https://github.com/joBr99/nspanel-lovelace-ui/wiki

          NSPanel Adapter Wiki
          https://github.com/ticaki/ioBroker.nspanel-lovelace-ui/wiki

          1 Antwort Letzte Antwort
          0
          • K kptkip

            @TT-Tom

            Cool, das geht definitv in die richtige Richtung. Allerdings findet die tibber-API (die zapfe ich nämlich an) da etwas nicht in Ordnung:

            {
              "errors": [
                {
                  "message": "GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension.",
                  "extensions": {
                    "code": "INTERNAL_SERVER_ERROR",
                    "exception": {
                      "stacktrace": [
                        "GraphQLError: GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension.",
                        " at processGraphQLRequest (/app/node_modules/apollo-server-core/dist/requestPipeline.js:73:40)",
                        " at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
                        " at async processHTTPRequest (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:222:30)"
                      ]
                    }
                  }
                }
              ]
            }
            

            Ich kopier mal das Originalscript (mit Workaround) in voller Länge hier rein, vlt. wird die Erwartung der API deutlicher:

            const request = require('request');
            
            //Get Token from Tibber
            var LoginUri = "https://app.tibber.com/login.credentials";
            var output = "1";
            var params = {
              "@type": "login",
              "email": [EMAIL],
              'password': [PASSWD]};
            
            //Using the request.post function to send a POST request with JSON data
            request.post({
              url: LoginUri,
              json: params
            }, function(error, response, body) {
              if (error) {
                console.error(error);
              } else {
                var TokenFromLogin = body.token;
                //console.log(TokenFromLogin);
            
                //Request Battery Status
                var uri = "https://app.tibber.com/v4/gql?query={me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}";
                var Token = TokenFromLogin;
                //Using the request.post function to send a POST request with a Bearer token
                  request.post({
                      url: uri,
                      headers: {
                          'Authorization': 'Bearer ' + Token
                      }
                  }, function (error, response, body) {
                      if (error) {
                          console.error(error);
            
                      } else {
                          //console.log(body);
                          output = body;
                          setState("0_userdata.0.Polestar.Tibber_Response", output);
            
                      }
                  });
              }
            });
            
            T Offline
            T Offline
            TT-Tom
            schrieb am zuletzt editiert von
            #43

            @kptkip

            hier mal zum Testen und bitte ggf bei Fehler das Log posten.

            //Get Token from Tibber
            const LoginUri = 'https://app.tibber.com/login.credentials';
            const uri = 'https://app.tibber.com/v4/gql?query={me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}';
            let output = '1';
            let TokenFromLogin = '';
            const params = {
                '@type': 'login',
                email: [EMAIL],
                password: [PASSWD],
            };
            
            //Using the request.post function to send a POST request with JSON data
            httpPost(LoginUri, { params }, (error, response) => {
                if (error) {
                    log(error, 'error');
                } else {
                    log(response.statusCode);
                    log(response.data);
                    TokenFromLogin = response.data;
            
                    //Request Battery Status
            
                    //Using the request.post function to send a POST request with a Bearer token
                    httpPost(uri, { headers: { Authorization: 'Bearer ' + TokenFromLogin } }, (error, response) => {
                        if (!error) {
                            log(response.statusCode);
                            log(response.data);
                            log(response.headers);
                            output = response.data;
                            setState('0_userdata.0.Polestar.Tibber_Response', output);
                        } else {
                            log(error, 'error');
                        }
                    });
                }
            });
            

            Gruß Tom
            https://github.com/tt-tom17
            Wenn meine Hilfe erfolgreich war, benutze bitte das Voting unten rechts im Beitrag

            NSPanel Script Wiki
            https://github.com/joBr99/nspanel-lovelace-ui/wiki

            NSPanel Adapter Wiki
            https://github.com/ticaki/ioBroker.nspanel-lovelace-ui/wiki

            K 1 Antwort Letzte Antwort
            2
            • T TT-Tom

              @kptkip

              hier mal zum Testen und bitte ggf bei Fehler das Log posten.

              //Get Token from Tibber
              const LoginUri = 'https://app.tibber.com/login.credentials';
              const uri = 'https://app.tibber.com/v4/gql?query={me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}';
              let output = '1';
              let TokenFromLogin = '';
              const params = {
                  '@type': 'login',
                  email: [EMAIL],
                  password: [PASSWD],
              };
              
              //Using the request.post function to send a POST request with JSON data
              httpPost(LoginUri, { params }, (error, response) => {
                  if (error) {
                      log(error, 'error');
                  } else {
                      log(response.statusCode);
                      log(response.data);
                      TokenFromLogin = response.data;
              
                      //Request Battery Status
              
                      //Using the request.post function to send a POST request with a Bearer token
                      httpPost(uri, { headers: { Authorization: 'Bearer ' + TokenFromLogin } }, (error, response) => {
                          if (!error) {
                              log(response.statusCode);
                              log(response.data);
                              log(response.headers);
                              output = response.data;
                              setState('0_userdata.0.Polestar.Tibber_Response', output);
                          } else {
                              log(error, 'error');
                          }
                      });
                  }
              });
              
              K Offline
              K Offline
              kptkip
              schrieb am zuletzt editiert von kptkip
              #44

              Hey @tt-tom !

              Sorry, Update, es klappt doch nicht. war zu schnell.

              Hier das log:

              script.js.Strom_und_PV.Tibber_Polestar_SOC: 400
              javascript.0	20:16:00.186	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"error":"To login you need to type in both your email and your password."}
              javascript.0	20:16:00.359	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 400
              javascript.0	20:16:00.359	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":[{"message":"GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension.","extensions":{"code":"INTERNAL_SERVER_ERROR","exception":{"stacktrace":["GraphQLError: GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension."," at processGraphQLRequest (/app/node_modules/apollo-server-core/dist/requestPipeline.js:73:40)"," at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"," at async processHTTPRequest (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:222:30)"]}}}]}
              javascript.0	20:16:00.360	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: Object [AxiosHeaders] { date: 'Sat, 01 Jun 2024 18:16:09 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '573', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '*', etag: 'W/"23d-S8aiZRFOGuFbW0vwnvg3M2ft9pA"', vary: 'Accept-Encoding' }
              

              Kann es sein, dass der Aufruf hier:

              httpPost(LoginUri, { params }, (error, response) => {
              

              das JSON-Objekt nicht kenntlich macht. Also, dass die API das nicht auseinander sortiert?
              Im Originalscript wird das mit json: params angegeben. Oder sollen die geschweiften Klammern das machen?

              haus-automatisierungH 1 Antwort Letzte Antwort
              0
              • K kptkip

                Hey @tt-tom !

                Sorry, Update, es klappt doch nicht. war zu schnell.

                Hier das log:

                script.js.Strom_und_PV.Tibber_Polestar_SOC: 400
                javascript.0	20:16:00.186	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"error":"To login you need to type in both your email and your password."}
                javascript.0	20:16:00.359	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 400
                javascript.0	20:16:00.359	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":[{"message":"GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension.","extensions":{"code":"INTERNAL_SERVER_ERROR","exception":{"stacktrace":["GraphQLError: GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension."," at processGraphQLRequest (/app/node_modules/apollo-server-core/dist/requestPipeline.js:73:40)"," at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"," at async processHTTPRequest (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:222:30)"]}}}]}
                javascript.0	20:16:00.360	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: Object [AxiosHeaders] { date: 'Sat, 01 Jun 2024 18:16:09 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '573', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '*', etag: 'W/"23d-S8aiZRFOGuFbW0vwnvg3M2ft9pA"', vary: 'Accept-Encoding' }
                

                Kann es sein, dass der Aufruf hier:

                httpPost(LoginUri, { params }, (error, response) => {
                

                das JSON-Objekt nicht kenntlich macht. Also, dass die API das nicht auseinander sortiert?
                Im Originalscript wird das mit json: params angegeben. Oder sollen die geschweiften Klammern das machen?

                haus-automatisierungH Online
                haus-automatisierungH Online
                haus-automatisierung
                Developer Most Active
                schrieb am zuletzt editiert von
                #45

                @kptkip Params ist schon ein Objekt. Also nicht nochmal in ein Objekt wrappen:

                // Get Token from Tibber
                const loginUri = 'https://app.tibber.com/login.credentials';
                const uri = 'https://app.tibber.com/v4/gql?query={me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}';
                
                let output = '1';
                let tokenFromLogin = '';
                
                const postData = {
                    '@type': 'login',
                    email: [EMAIL],
                    password: [PASSWD],
                };
                
                // Using the request.post function to send a POST request with JSON data
                httpPost(loginUri, postData, (error, response) => {
                    if (error) {
                        log(error, 'error');
                    } else {
                        log(response.statusCode);
                        log(response.data);
                
                        tokenFromLogin = response.data;
                
                        // Request Battery Status
                        // Using the request.post function to send a POST request with a Bearer token
                        httpPost(uri, { bearerAuth: tokenFromLogin }, (error, response) => {
                            if (!error) {
                                log(response.statusCode);
                                log(response.data);
                                log(response.headers);
                                output = response.data;
                
                                setState('0_userdata.0.Polestar.Tibber_Response', output);
                            } else {
                                log(error, 'error');
                            }
                        });
                    }
                });
                
                

                🧑‍🎓 Autor des beliebten ioBroker-Master-Kurses
                🎥 Tutorials rund um das Thema DIY-Smart-Home: https://haus-automatisierung.com/
                📚 Meine inoffizielle ioBroker Dokumentation

                T K 2 Antworten Letzte Antwort
                2
                • haus-automatisierungH haus-automatisierung

                  @kptkip Params ist schon ein Objekt. Also nicht nochmal in ein Objekt wrappen:

                  // Get Token from Tibber
                  const loginUri = 'https://app.tibber.com/login.credentials';
                  const uri = 'https://app.tibber.com/v4/gql?query={me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}';
                  
                  let output = '1';
                  let tokenFromLogin = '';
                  
                  const postData = {
                      '@type': 'login',
                      email: [EMAIL],
                      password: [PASSWD],
                  };
                  
                  // Using the request.post function to send a POST request with JSON data
                  httpPost(loginUri, postData, (error, response) => {
                      if (error) {
                          log(error, 'error');
                      } else {
                          log(response.statusCode);
                          log(response.data);
                  
                          tokenFromLogin = response.data;
                  
                          // Request Battery Status
                          // Using the request.post function to send a POST request with a Bearer token
                          httpPost(uri, { bearerAuth: tokenFromLogin }, (error, response) => {
                              if (!error) {
                                  log(response.statusCode);
                                  log(response.data);
                                  log(response.headers);
                                  output = response.data;
                  
                                  setState('0_userdata.0.Polestar.Tibber_Response', output);
                              } else {
                                  log(error, 'error');
                              }
                          });
                      }
                  });
                  
                  
                  T Offline
                  T Offline
                  TT-Tom
                  schrieb am zuletzt editiert von
                  #46

                  @haus-automatisierung
                  ja, da war ich etwas überfragt, ob mit Klammern oder ohne. Danke für die Hilfe. :+1:

                  Gruß Tom
                  https://github.com/tt-tom17
                  Wenn meine Hilfe erfolgreich war, benutze bitte das Voting unten rechts im Beitrag

                  NSPanel Script Wiki
                  https://github.com/joBr99/nspanel-lovelace-ui/wiki

                  NSPanel Adapter Wiki
                  https://github.com/ticaki/ioBroker.nspanel-lovelace-ui/wiki

                  1 Antwort Letzte Antwort
                  0
                  • haus-automatisierungH haus-automatisierung

                    @kptkip Params ist schon ein Objekt. Also nicht nochmal in ein Objekt wrappen:

                    // Get Token from Tibber
                    const loginUri = 'https://app.tibber.com/login.credentials';
                    const uri = 'https://app.tibber.com/v4/gql?query={me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}';
                    
                    let output = '1';
                    let tokenFromLogin = '';
                    
                    const postData = {
                        '@type': 'login',
                        email: [EMAIL],
                        password: [PASSWD],
                    };
                    
                    // Using the request.post function to send a POST request with JSON data
                    httpPost(loginUri, postData, (error, response) => {
                        if (error) {
                            log(error, 'error');
                        } else {
                            log(response.statusCode);
                            log(response.data);
                    
                            tokenFromLogin = response.data;
                    
                            // Request Battery Status
                            // Using the request.post function to send a POST request with a Bearer token
                            httpPost(uri, { bearerAuth: tokenFromLogin }, (error, response) => {
                                if (!error) {
                                    log(response.statusCode);
                                    log(response.data);
                                    log(response.headers);
                                    output = response.data;
                    
                                    setState('0_userdata.0.Polestar.Tibber_Response', output);
                                } else {
                                    log(error, 'error');
                                }
                            });
                        }
                    });
                    
                    
                    K Offline
                    K Offline
                    kptkip
                    schrieb am zuletzt editiert von kptkip
                    #47

                    @haus-automatisierung

                    Der erste call klappt nun. Danke! :-)

                    Ich denke beim zweiten, bei dem die Daten abgeholt werden gibts noch ein Problem:

                    javascript.0	09:02:00.246	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 200
                    javascript.0	09:02:00.246	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"token":"SuperToken"}
                    javascript.0	09:02:00.477	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 400
                    javascript.0	09:02:00.477	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":[{"message":"GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension.","extensions":{"code":"INTERNAL_SERVER_ERROR","exception":{"stacktrace":["GraphQLError: GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension."," at processGraphQLRequest (/app/node_modules/apollo-server-core/dist/requestPipeline.js:73:40)"," at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"," at async processHTTPRequest (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:222:30)"]}}}]}
                    javascript.0	09:02:00.477	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: Object [AxiosHeaders] { date: 'Sun, 02 Jun 2024 07:02:10 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '573', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '*', etag: 'W/"23d-S8aiZRFOGuFbW0vwnvg3M2ft9pA"', vary: 'Accept-Encoding' }
                    

                    Es scheinen noch nicht alle Daten übermittelt zu werden, wenn ich das richtig verstehe:
                    "must contain a non-empty 'query'"

                    T 1 Antwort Letzte Antwort
                    0
                    • K kptkip

                      @haus-automatisierung

                      Der erste call klappt nun. Danke! :-)

                      Ich denke beim zweiten, bei dem die Daten abgeholt werden gibts noch ein Problem:

                      javascript.0	09:02:00.246	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 200
                      javascript.0	09:02:00.246	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"token":"SuperToken"}
                      javascript.0	09:02:00.477	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 400
                      javascript.0	09:02:00.477	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":[{"message":"GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension.","extensions":{"code":"INTERNAL_SERVER_ERROR","exception":{"stacktrace":["GraphQLError: GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension."," at processGraphQLRequest (/app/node_modules/apollo-server-core/dist/requestPipeline.js:73:40)"," at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"," at async processHTTPRequest (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:222:30)"]}}}]}
                      javascript.0	09:02:00.477	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: Object [AxiosHeaders] { date: 'Sun, 02 Jun 2024 07:02:10 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '573', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '*', etag: 'W/"23d-S8aiZRFOGuFbW0vwnvg3M2ft9pA"', vary: 'Accept-Encoding' }
                      

                      Es scheinen noch nicht alle Daten übermittelt zu werden, wenn ich das richtig verstehe:
                      "must contain a non-empty 'query'"

                      T Offline
                      T Offline
                      TT-Tom
                      schrieb am zuletzt editiert von
                      #48

                      @kptkip

                      im Original steht

                      headers: {
                                    'Authorization': 'Bearer ' + Token
                                }
                      

                      da wird das Wort Bearer vor den Token gesetzt mit einem Leerzeichen.

                      ändere mal diese Zeile

                      tokenFromLogin = response.data;
                      

                      in diese um

                      tokenFromLogin = 'Bearer ' + response.data;
                      

                      Wenn dies auch wieder zu Fehler führt wäre das nochmal ein Versuch

                              httpPost(uri, { headers: { Authorization: 'Bearer ' + TokenFromLogin } }, (error, response) => {
                                  if (!error) {
                                      log(response.statusCode);
                                      log(response.data);
                                      log(response.headers);
                                      output = response.data;
                                      setState('0_userdata.0.Polestar.Tibber_Response', output);
                                  } else {
                                      log(error, 'error');
                                  }
                              });
                      

                      dann bin ich aber auch mit mein Latein am Ende.

                      Gruß Tom
                      https://github.com/tt-tom17
                      Wenn meine Hilfe erfolgreich war, benutze bitte das Voting unten rechts im Beitrag

                      NSPanel Script Wiki
                      https://github.com/joBr99/nspanel-lovelace-ui/wiki

                      NSPanel Adapter Wiki
                      https://github.com/ticaki/ioBroker.nspanel-lovelace-ui/wiki

                      1 Antwort Letzte Antwort
                      0
                      • K Offline
                        K Offline
                        kptkip
                        schrieb am zuletzt editiert von kptkip
                        #49

                        Klappt auch nicht.

                        Nachdem ich trotz Google nichts passendes gefunden habe, gehe ich als Hypothese davon aus, dass:

                        { bearerAuth: tokenFromLogin }
                        

                        genau den Authentifizierungs-Mechanismus per "Bearer" auslösen soll.

                        Was mich bei der Fehlermeldung irritiert, ist die Meldung, dass Inhalte leer wären. Im Prinzip muss die URL (habs im Browser getestet - im eingeloggten Zustand) nur abgesetzt werden und im Header der Token mitgegeben werden. Frage mich, wo er noch Inhalte haben möchte?

                        BTW: Wenn ich nach "Javascript" und "httpPost()" google, finde ich keine vernünftige Erläuterung oder Doku. Zumindest nicht, wie das hier verwendet wird.
                        Das Einzige als Treffer sind dann Anleitungen und Dokus zum Befehl "fetch()" (klappt hier auch nur mit explizitem require('fetch') und nicht freiweg ) oder zu axios. Vlt. bin ich aber auch nicht schlau genug, zum Suchen.

                        haus-automatisierungH T 2 Antworten Letzte Antwort
                        0
                        • K kptkip

                          Klappt auch nicht.

                          Nachdem ich trotz Google nichts passendes gefunden habe, gehe ich als Hypothese davon aus, dass:

                          { bearerAuth: tokenFromLogin }
                          

                          genau den Authentifizierungs-Mechanismus per "Bearer" auslösen soll.

                          Was mich bei der Fehlermeldung irritiert, ist die Meldung, dass Inhalte leer wären. Im Prinzip muss die URL (habs im Browser getestet - im eingeloggten Zustand) nur abgesetzt werden und im Header der Token mitgegeben werden. Frage mich, wo er noch Inhalte haben möchte?

                          BTW: Wenn ich nach "Javascript" und "httpPost()" google, finde ich keine vernünftige Erläuterung oder Doku. Zumindest nicht, wie das hier verwendet wird.
                          Das Einzige als Treffer sind dann Anleitungen und Dokus zum Befehl "fetch()" (klappt hier auch nur mit explizitem require('fetch') und nicht freiweg ) oder zu axios. Vlt. bin ich aber auch nicht schlau genug, zum Suchen.

                          haus-automatisierungH Online
                          haus-automatisierungH Online
                          haus-automatisierung
                          Developer Most Active
                          schrieb am zuletzt editiert von haus-automatisierung
                          #50

                          @kptkip sagte in Plötzlich ReferenceError: request is not defined:

                          BTW: Wenn ich nach "Javascript" und "httpPost()" google, finde ich keine vernünftige Erläuterung oder Doku.

                          Das ist ja auch ioBroker spezifisch und ein Wrapper für axios in der JavaScript-Sandbox. Damit wir in Zukunft die darunter liegende Library austauschen können, und trotzdem alles weiter funktioniert. Demnach auch nur hier dokumentiert:

                          https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/en/javascript.md#httpget

                          EDIT: Ich sehe gerade, dass der zweite Aufruf ja auch ein httpPost ist. Dann müssen natürlich die Daten mitgegeben werden. Sicher, dass das ein Post-Request sein muss (wozu? Da werden ja Get-Parameter genutzt für den Query). Teste mal so:

                          // Get Token from Tibber
                          const loginUri = 'https://app.tibber.com/login.credentials';
                          const uri = 'https://app.tibber.com/v4/gql?query={me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}';
                           
                          let output = '1';
                          let tokenFromLogin = '';
                           
                          const postData = {
                              '@type': 'login',
                              email: [EMAIL],
                              password: [PASSWD],
                          };
                           
                          // Using the request.post function to send a POST request with JSON data
                          httpPost(loginUri, postData, (error, response) => {
                              if (error) {
                                  log(error, 'error');
                              } else {
                                  log(response.statusCode);
                                  log(response.data);
                           
                                  tokenFromLogin = response.data;
                           
                                  // Request Battery Status
                                  // Using the request.post function to send a POST request with a Bearer token
                                  httpPost(uri, {}, { bearerAuth: tokenFromLogin }, (error, response) => {
                                      if (!error) {
                                          log(response.statusCode);
                                          log(response.data);
                                          log(response.headers);
                                          output = response.data;
                           
                                          setState('0_userdata.0.Polestar.Tibber_Response', output);
                                      } else {
                                          log(error, 'error');
                                      }
                                  });
                              }
                          });
                          

                          Alternativ den Query per Post senden:

                          // Get Token from Tibber
                          const loginUri = 'https://app.tibber.com/login.credentials';
                          const uri = 'https://app.tibber.com/v4/gql';
                           
                          let output = '1';
                          let tokenFromLogin = '';
                           
                          const postData = {
                              '@type': 'login',
                              email: [EMAIL],
                              password: [PASSWD],
                          };
                           
                          // Using the request.post function to send a POST request with JSON data
                          httpPost(loginUri, postData, (error, response) => {
                              if (error) {
                                  log(error, 'error');
                              } else {
                                  log(response.statusCode);
                                  log(response.data);
                           
                                  tokenFromLogin = response.data;
                           
                                  // Request Battery Status
                                  // Using the request.post function to send a POST request with a Bearer token
                                  httpPost(uri, { query: '{me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}' }, { bearerAuth: tokenFromLogin }, (error, response) => {
                                      if (!error) {
                                          log(response.statusCode);
                                          log(response.data);
                                          log(response.headers);
                                          output = response.data;
                           
                                          setState('0_userdata.0.Polestar.Tibber_Response', output);
                                      } else {
                                          log(error, 'error');
                                      }
                                  });
                              }
                          });
                          

                          🧑‍🎓 Autor des beliebten ioBroker-Master-Kurses
                          🎥 Tutorials rund um das Thema DIY-Smart-Home: https://haus-automatisierung.com/
                          📚 Meine inoffizielle ioBroker Dokumentation

                          K 1 Antwort Letzte Antwort
                          0
                          • K kptkip

                            Klappt auch nicht.

                            Nachdem ich trotz Google nichts passendes gefunden habe, gehe ich als Hypothese davon aus, dass:

                            { bearerAuth: tokenFromLogin }
                            

                            genau den Authentifizierungs-Mechanismus per "Bearer" auslösen soll.

                            Was mich bei der Fehlermeldung irritiert, ist die Meldung, dass Inhalte leer wären. Im Prinzip muss die URL (habs im Browser getestet - im eingeloggten Zustand) nur abgesetzt werden und im Header der Token mitgegeben werden. Frage mich, wo er noch Inhalte haben möchte?

                            BTW: Wenn ich nach "Javascript" und "httpPost()" google, finde ich keine vernünftige Erläuterung oder Doku. Zumindest nicht, wie das hier verwendet wird.
                            Das Einzige als Treffer sind dann Anleitungen und Dokus zum Befehl "fetch()" (klappt hier auch nur mit explizitem require('fetch') und nicht freiweg ) oder zu axios. Vlt. bin ich aber auch nicht schlau genug, zum Suchen.

                            T Offline
                            T Offline
                            TT-Tom
                            schrieb am zuletzt editiert von TT-Tom
                            #51

                            @kptkip sagte in Plötzlich ReferenceError: request is not defined:

                            Nachdem ich trotz Google nichts passendes gefunden habe, gehe ich als Hypothese davon aus, dass:

                            { bearerAuth: tokenFromLogin }
                            

                            genau den Authentifizierungs-Mechanismus per "Bearer" auslösen soll.

                            Das habe ich in der Doku auch so gefunden, was mir nicht klar ist/war, das Wort Bearer wird das jetzt automatisch vor den Token gesetzt? @haus-automatisierung Denn in deinem Original-Script war es zusätzlich zum Token angehängt.

                            Gruß Tom
                            https://github.com/tt-tom17
                            Wenn meine Hilfe erfolgreich war, benutze bitte das Voting unten rechts im Beitrag

                            NSPanel Script Wiki
                            https://github.com/joBr99/nspanel-lovelace-ui/wiki

                            NSPanel Adapter Wiki
                            https://github.com/ticaki/ioBroker.nspanel-lovelace-ui/wiki

                            1 Antwort Letzte Antwort
                            0
                            • haus-automatisierungH haus-automatisierung

                              @kptkip sagte in Plötzlich ReferenceError: request is not defined:

                              BTW: Wenn ich nach "Javascript" und "httpPost()" google, finde ich keine vernünftige Erläuterung oder Doku.

                              Das ist ja auch ioBroker spezifisch und ein Wrapper für axios in der JavaScript-Sandbox. Damit wir in Zukunft die darunter liegende Library austauschen können, und trotzdem alles weiter funktioniert. Demnach auch nur hier dokumentiert:

                              https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/en/javascript.md#httpget

                              EDIT: Ich sehe gerade, dass der zweite Aufruf ja auch ein httpPost ist. Dann müssen natürlich die Daten mitgegeben werden. Sicher, dass das ein Post-Request sein muss (wozu? Da werden ja Get-Parameter genutzt für den Query). Teste mal so:

                              // Get Token from Tibber
                              const loginUri = 'https://app.tibber.com/login.credentials';
                              const uri = 'https://app.tibber.com/v4/gql?query={me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}';
                               
                              let output = '1';
                              let tokenFromLogin = '';
                               
                              const postData = {
                                  '@type': 'login',
                                  email: [EMAIL],
                                  password: [PASSWD],
                              };
                               
                              // Using the request.post function to send a POST request with JSON data
                              httpPost(loginUri, postData, (error, response) => {
                                  if (error) {
                                      log(error, 'error');
                                  } else {
                                      log(response.statusCode);
                                      log(response.data);
                               
                                      tokenFromLogin = response.data;
                               
                                      // Request Battery Status
                                      // Using the request.post function to send a POST request with a Bearer token
                                      httpPost(uri, {}, { bearerAuth: tokenFromLogin }, (error, response) => {
                                          if (!error) {
                                              log(response.statusCode);
                                              log(response.data);
                                              log(response.headers);
                                              output = response.data;
                               
                                              setState('0_userdata.0.Polestar.Tibber_Response', output);
                                          } else {
                                              log(error, 'error');
                                          }
                                      });
                                  }
                              });
                              

                              Alternativ den Query per Post senden:

                              // Get Token from Tibber
                              const loginUri = 'https://app.tibber.com/login.credentials';
                              const uri = 'https://app.tibber.com/v4/gql';
                               
                              let output = '1';
                              let tokenFromLogin = '';
                               
                              const postData = {
                                  '@type': 'login',
                                  email: [EMAIL],
                                  password: [PASSWD],
                              };
                               
                              // Using the request.post function to send a POST request with JSON data
                              httpPost(loginUri, postData, (error, response) => {
                                  if (error) {
                                      log(error, 'error');
                                  } else {
                                      log(response.statusCode);
                                      log(response.data);
                               
                                      tokenFromLogin = response.data;
                               
                                      // Request Battery Status
                                      // Using the request.post function to send a POST request with a Bearer token
                                      httpPost(uri, { query: '{me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}' }, { bearerAuth: tokenFromLogin }, (error, response) => {
                                          if (!error) {
                                              log(response.statusCode);
                                              log(response.data);
                                              log(response.headers);
                                              output = response.data;
                               
                                              setState('0_userdata.0.Polestar.Tibber_Response', output);
                                          } else {
                                              log(error, 'error');
                                          }
                                      });
                                  }
                              });
                              
                              K Offline
                              K Offline
                              kptkip
                              schrieb am zuletzt editiert von kptkip
                              #52

                              @haus-automatisierung said in Plötzlich ReferenceError: request is not defined:

                              Das ist ja auch ioBroker spezifisch und ein Wrapper für axios in der JavaScript-Sandbox. Damit wir in Zukunft die darunter liegende Library austauschen können, und trotzdem alles weiter funktioniert. Demnach auch nur hier dokumentiert:

                              https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/en/javascript.md#httpget

                              Danke für den hint mit dem Wrapper und den Link ;-)

                              Das mit dem Hinweis auf GET ist ein guter, da tatsächlich keine Daten (abgesehen vom Header) übermittelt werden. Das macht Sinn.

                              Allerdings klappt es noch nicht. Hier mal die Ergebnisse (POST und GET):

                              Mit POST:

                              httpPost(uri, {}, { bearerAuth: tokenFromLogin }, (error, response) => {
                              

                              ergibt folgende Fehler:

                              javascript.0	11:37:00.464	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 401
                              javascript.0	11:37:00.465	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":"Not authenticated. Login at: https://app.tibber.com/login"}
                              javascript.0	11:37:00.465	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: Object [AxiosHeaders] { date: 'Sun, 02 Jun 2024 09:37:10 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '71', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '*', etag: 'W/"47-pLydXmqqqWtGzFFyAjprzeLl/Aw"', vary: 'Accept-Encoding' }
                              

                              Per GET mit:

                              httpGet(uri, { bearerAuth: tokenFromLogin }, (error, response) => {
                              

                              oder:

                              httpGet(uri, { headers: { Authorization: 'Bearer ' + tokenFromLogin } }, (error, response) => {
                              

                              liefert er:

                              javascript.0	11:34:00.343	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 401
                              javascript.0	11:34:00.343	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":"Not authenticated. Login at: https://app.tibber.com/login"}
                              javascript.0	11:34:00.343	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: Object [AxiosHeaders] { date: 'Sun, 02 Jun 2024 09:34:10 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '71', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '*', etag: 'W/"47-pLydXmqqqWtGzFFyAjprzeLl/Aw"', vary: 'Accept-Encoding' }
                              

                              Die zusätzliche Query-Variante ist ganz wuschig:

                              httpPost(uri, { query: '{me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}' }, { bearerAuth: tokenFromLogin }, (error, response) => {
                              

                              Das ergibt folgende Fehler:

                              javascript.0	11:30:00.403	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 400
                              javascript.0	11:30:00.403	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":[{"message":"Syntax Error: Unexpected character: \"%\".","extensions":{"code":"GRAPHQL_PARSE_FAILED","exception":{"stacktrace":["GraphQLError: Syntax Error: Unexpected character: \"%\"."," at syntaxError (/app/node_modules/graphql/error/syntaxError.js:15:10)"," at readNextToken (/app/node_modules/graphql/language/lexer.js:420:40)"," at Lexer.lookahead (/app/node_modules/graphql/language/lexer.js:84:29)"," at Lexer.advance (/app/node_modules/graphql/language/lexer.js:67:38)"," at Parser.advanceLexer (/app/node_modules/graphql/language/parser.js:1536:31)"," at Parser.expectToken (/app/node_modules/graphql/language/parser.js:1393:12)"," at Parser.parseName (/app/node_modules/graphql/language/parser.js:108:24)"," at Parser.parseField (/app/node_modules/graphql/language/parser.js:347:30)"," at Parser.parseSelection (/app/node_modules/graphql/language/parser.js:337:14)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseSelectionSet (/app/node_modules/graphql/language/parser.js:320:24)"," at Parser.parseField (/app/node_modules/graphql/language/parser.js:365:16)"," at Parser.parseSelection (/app/node_modules/graphql/language/parser.js:337:14)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseSelectionSet (/app/node_modules/graphql/language/parser.js:320:24)"," at Parser.parseField (/app/node_modules/graphql/language/parser.js:365:16)"," at Parser.parseSelection (/app/node_modules/graphql/language/parser.js:337:14)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseSelectionSet (/app/node_modules/graphql/language/parser.js:320:24)"," at Parser.parseField (/app/node_modules/graphql/language/parser.js:365:16)"," at Parser.parseSelection (/app/node_modules/graphql/language/parser.js:337:14)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseSelectionSet (/app/node_modules/graphql/language/parser.js:320:24)"," at Parser.parseOperationDefinition (/app/node_modules/graphql/language/parser.js:231:28)"," at Parser.parseDefinition (/app/node_modules/graphql/language/parser.js:155:19)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseDocument (/app/node_modules/graphql/language/parser.js:122:25)"," at parse (/app/node_modules/graphql/language/parser.js:32:17)"," at parse (/app/node_modules/apollo-server-core/dist/requestPipeline.js:181:36)"," at processGraphQLRequest (/app/node_modules/apollo-server-core/dist/requestPipeline.js:90:39)"," at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"," at async processHTTPRequest (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:222:30)"]}}}]}
                              

                              In allen Fällen klappt es mit der Authentifizierung per Bearer-Header nicht wie gewünscht.

                              T haus-automatisierungH 2 Antworten Letzte Antwort
                              0
                              • K kptkip

                                @haus-automatisierung said in Plötzlich ReferenceError: request is not defined:

                                Das ist ja auch ioBroker spezifisch und ein Wrapper für axios in der JavaScript-Sandbox. Damit wir in Zukunft die darunter liegende Library austauschen können, und trotzdem alles weiter funktioniert. Demnach auch nur hier dokumentiert:

                                https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/en/javascript.md#httpget

                                Danke für den hint mit dem Wrapper und den Link ;-)

                                Das mit dem Hinweis auf GET ist ein guter, da tatsächlich keine Daten (abgesehen vom Header) übermittelt werden. Das macht Sinn.

                                Allerdings klappt es noch nicht. Hier mal die Ergebnisse (POST und GET):

                                Mit POST:

                                httpPost(uri, {}, { bearerAuth: tokenFromLogin }, (error, response) => {
                                

                                ergibt folgende Fehler:

                                javascript.0	11:37:00.464	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 401
                                javascript.0	11:37:00.465	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":"Not authenticated. Login at: https://app.tibber.com/login"}
                                javascript.0	11:37:00.465	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: Object [AxiosHeaders] { date: 'Sun, 02 Jun 2024 09:37:10 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '71', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '*', etag: 'W/"47-pLydXmqqqWtGzFFyAjprzeLl/Aw"', vary: 'Accept-Encoding' }
                                

                                Per GET mit:

                                httpGet(uri, { bearerAuth: tokenFromLogin }, (error, response) => {
                                

                                oder:

                                httpGet(uri, { headers: { Authorization: 'Bearer ' + tokenFromLogin } }, (error, response) => {
                                

                                liefert er:

                                javascript.0	11:34:00.343	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 401
                                javascript.0	11:34:00.343	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":"Not authenticated. Login at: https://app.tibber.com/login"}
                                javascript.0	11:34:00.343	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: Object [AxiosHeaders] { date: 'Sun, 02 Jun 2024 09:34:10 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '71', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '*', etag: 'W/"47-pLydXmqqqWtGzFFyAjprzeLl/Aw"', vary: 'Accept-Encoding' }
                                

                                Die zusätzliche Query-Variante ist ganz wuschig:

                                httpPost(uri, { query: '{me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}' }, { bearerAuth: tokenFromLogin }, (error, response) => {
                                

                                Das ergibt folgende Fehler:

                                javascript.0	11:30:00.403	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 400
                                javascript.0	11:30:00.403	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":[{"message":"Syntax Error: Unexpected character: \"%\".","extensions":{"code":"GRAPHQL_PARSE_FAILED","exception":{"stacktrace":["GraphQLError: Syntax Error: Unexpected character: \"%\"."," at syntaxError (/app/node_modules/graphql/error/syntaxError.js:15:10)"," at readNextToken (/app/node_modules/graphql/language/lexer.js:420:40)"," at Lexer.lookahead (/app/node_modules/graphql/language/lexer.js:84:29)"," at Lexer.advance (/app/node_modules/graphql/language/lexer.js:67:38)"," at Parser.advanceLexer (/app/node_modules/graphql/language/parser.js:1536:31)"," at Parser.expectToken (/app/node_modules/graphql/language/parser.js:1393:12)"," at Parser.parseName (/app/node_modules/graphql/language/parser.js:108:24)"," at Parser.parseField (/app/node_modules/graphql/language/parser.js:347:30)"," at Parser.parseSelection (/app/node_modules/graphql/language/parser.js:337:14)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseSelectionSet (/app/node_modules/graphql/language/parser.js:320:24)"," at Parser.parseField (/app/node_modules/graphql/language/parser.js:365:16)"," at Parser.parseSelection (/app/node_modules/graphql/language/parser.js:337:14)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseSelectionSet (/app/node_modules/graphql/language/parser.js:320:24)"," at Parser.parseField (/app/node_modules/graphql/language/parser.js:365:16)"," at Parser.parseSelection (/app/node_modules/graphql/language/parser.js:337:14)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseSelectionSet (/app/node_modules/graphql/language/parser.js:320:24)"," at Parser.parseField (/app/node_modules/graphql/language/parser.js:365:16)"," at Parser.parseSelection (/app/node_modules/graphql/language/parser.js:337:14)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseSelectionSet (/app/node_modules/graphql/language/parser.js:320:24)"," at Parser.parseOperationDefinition (/app/node_modules/graphql/language/parser.js:231:28)"," at Parser.parseDefinition (/app/node_modules/graphql/language/parser.js:155:19)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseDocument (/app/node_modules/graphql/language/parser.js:122:25)"," at parse (/app/node_modules/graphql/language/parser.js:32:17)"," at parse (/app/node_modules/apollo-server-core/dist/requestPipeline.js:181:36)"," at processGraphQLRequest (/app/node_modules/apollo-server-core/dist/requestPipeline.js:90:39)"," at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"," at async processHTTPRequest (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:222:30)"]}}}]}
                                

                                In allen Fällen klappt es mit der Authentifizierung per Bearer-Header nicht wie gewünscht.

                                T Offline
                                T Offline
                                TT-Tom
                                schrieb am zuletzt editiert von
                                #53

                                @kptkip sagte in Plötzlich ReferenceError: request is not defined:

                                %0A

                                bedeutet LF -> LineFeed

                                %20 ist das Leerzeichen

                                was ist wenn du die weg lässt

                                Gruß Tom
                                https://github.com/tt-tom17
                                Wenn meine Hilfe erfolgreich war, benutze bitte das Voting unten rechts im Beitrag

                                NSPanel Script Wiki
                                https://github.com/joBr99/nspanel-lovelace-ui/wiki

                                NSPanel Adapter Wiki
                                https://github.com/ticaki/ioBroker.nspanel-lovelace-ui/wiki

                                1 Antwort Letzte Antwort
                                1
                                • K kptkip

                                  @haus-automatisierung said in Plötzlich ReferenceError: request is not defined:

                                  Das ist ja auch ioBroker spezifisch und ein Wrapper für axios in der JavaScript-Sandbox. Damit wir in Zukunft die darunter liegende Library austauschen können, und trotzdem alles weiter funktioniert. Demnach auch nur hier dokumentiert:

                                  https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/en/javascript.md#httpget

                                  Danke für den hint mit dem Wrapper und den Link ;-)

                                  Das mit dem Hinweis auf GET ist ein guter, da tatsächlich keine Daten (abgesehen vom Header) übermittelt werden. Das macht Sinn.

                                  Allerdings klappt es noch nicht. Hier mal die Ergebnisse (POST und GET):

                                  Mit POST:

                                  httpPost(uri, {}, { bearerAuth: tokenFromLogin }, (error, response) => {
                                  

                                  ergibt folgende Fehler:

                                  javascript.0	11:37:00.464	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 401
                                  javascript.0	11:37:00.465	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":"Not authenticated. Login at: https://app.tibber.com/login"}
                                  javascript.0	11:37:00.465	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: Object [AxiosHeaders] { date: 'Sun, 02 Jun 2024 09:37:10 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '71', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '*', etag: 'W/"47-pLydXmqqqWtGzFFyAjprzeLl/Aw"', vary: 'Accept-Encoding' }
                                  

                                  Per GET mit:

                                  httpGet(uri, { bearerAuth: tokenFromLogin }, (error, response) => {
                                  

                                  oder:

                                  httpGet(uri, { headers: { Authorization: 'Bearer ' + tokenFromLogin } }, (error, response) => {
                                  

                                  liefert er:

                                  javascript.0	11:34:00.343	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 401
                                  javascript.0	11:34:00.343	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":"Not authenticated. Login at: https://app.tibber.com/login"}
                                  javascript.0	11:34:00.343	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: Object [AxiosHeaders] { date: 'Sun, 02 Jun 2024 09:34:10 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '71', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '*', etag: 'W/"47-pLydXmqqqWtGzFFyAjprzeLl/Aw"', vary: 'Accept-Encoding' }
                                  

                                  Die zusätzliche Query-Variante ist ganz wuschig:

                                  httpPost(uri, { query: '{me{homes{electricVehicles{lastSeen%0A%20 battery{percent}}}}}' }, { bearerAuth: tokenFromLogin }, (error, response) => {
                                  

                                  Das ergibt folgende Fehler:

                                  javascript.0	11:30:00.403	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: 400
                                  javascript.0	11:30:00.403	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"errors":[{"message":"Syntax Error: Unexpected character: \"%\".","extensions":{"code":"GRAPHQL_PARSE_FAILED","exception":{"stacktrace":["GraphQLError: Syntax Error: Unexpected character: \"%\"."," at syntaxError (/app/node_modules/graphql/error/syntaxError.js:15:10)"," at readNextToken (/app/node_modules/graphql/language/lexer.js:420:40)"," at Lexer.lookahead (/app/node_modules/graphql/language/lexer.js:84:29)"," at Lexer.advance (/app/node_modules/graphql/language/lexer.js:67:38)"," at Parser.advanceLexer (/app/node_modules/graphql/language/parser.js:1536:31)"," at Parser.expectToken (/app/node_modules/graphql/language/parser.js:1393:12)"," at Parser.parseName (/app/node_modules/graphql/language/parser.js:108:24)"," at Parser.parseField (/app/node_modules/graphql/language/parser.js:347:30)"," at Parser.parseSelection (/app/node_modules/graphql/language/parser.js:337:14)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseSelectionSet (/app/node_modules/graphql/language/parser.js:320:24)"," at Parser.parseField (/app/node_modules/graphql/language/parser.js:365:16)"," at Parser.parseSelection (/app/node_modules/graphql/language/parser.js:337:14)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseSelectionSet (/app/node_modules/graphql/language/parser.js:320:24)"," at Parser.parseField (/app/node_modules/graphql/language/parser.js:365:16)"," at Parser.parseSelection (/app/node_modules/graphql/language/parser.js:337:14)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseSelectionSet (/app/node_modules/graphql/language/parser.js:320:24)"," at Parser.parseField (/app/node_modules/graphql/language/parser.js:365:16)"," at Parser.parseSelection (/app/node_modules/graphql/language/parser.js:337:14)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseSelectionSet (/app/node_modules/graphql/language/parser.js:320:24)"," at Parser.parseOperationDefinition (/app/node_modules/graphql/language/parser.js:231:28)"," at Parser.parseDefinition (/app/node_modules/graphql/language/parser.js:155:19)"," at Parser.many (/app/node_modules/graphql/language/parser.js:1511:26)"," at Parser.parseDocument (/app/node_modules/graphql/language/parser.js:122:25)"," at parse (/app/node_modules/graphql/language/parser.js:32:17)"," at parse (/app/node_modules/apollo-server-core/dist/requestPipeline.js:181:36)"," at processGraphQLRequest (/app/node_modules/apollo-server-core/dist/requestPipeline.js:90:39)"," at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"," at async processHTTPRequest (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:222:30)"]}}}]}
                                  

                                  In allen Fällen klappt es mit der Authentifizierung per Bearer-Header nicht wie gewünscht.

                                  haus-automatisierungH Online
                                  haus-automatisierungH Online
                                  haus-automatisierung
                                  Developer Most Active
                                  schrieb am zuletzt editiert von
                                  #54

                                  @kptkip Sorry, ist recht schwer ohne einen Link auf die API-Doku alles zu raten :) @TT-Tom hat Recht, würde das auch einfach entfernen und testen.

                                  🧑‍🎓 Autor des beliebten ioBroker-Master-Kurses
                                  🎥 Tutorials rund um das Thema DIY-Smart-Home: https://haus-automatisierung.com/
                                  📚 Meine inoffizielle ioBroker Dokumentation

                                  K 1 Antwort Letzte Antwort
                                  0
                                  • haus-automatisierungH haus-automatisierung

                                    @kptkip Sorry, ist recht schwer ohne einen Link auf die API-Doku alles zu raten :) @TT-Tom hat Recht, würde das auch einfach entfernen und testen.

                                    K Offline
                                    K Offline
                                    kptkip
                                    schrieb am zuletzt editiert von kptkip
                                    #55

                                    @haus-automatisierung said in Plötzlich ReferenceError: request is not defined:

                                    @kptkip Sorry, ist recht schwer ohne einen Link auf die API-Doku alles zu raten :)

                                    Nur zur Vollständigkeit - die Tibber-API ist hier:
                                    https://developer.tibber.com/docs/overview

                                    @TT-Tom hat Recht, würde das auch einfach entfernen und testen.

                                    Mit der URL hab ich auch schon rumgespielt. Das ändert nichts. Würde mich ehrlich gesagt auch wundern. Die URL hat im Script mit request.post() wunderbar funktioniert. Sogar mit nicht-URL-encodetem Leerzeichen.

                                    [EDIT:]
                                    Ich habe immer noch die Vermutung, dass die neuen Functions httpPost() und httpGet() im JS-Wrapper die Header-Parameter nicht korrekt durchreichen.

                                    ~~Wenn ich mir das hier durchlese:
                                    https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-http/mc-ampscript-reference-http-post.html~~

                                    Komm ich zur Überlegung, ob das hier (oder axios) korrekt bedient wird:

                                    HttpPost(urlEndpoint,
                                             contentTypeHeader,
                                             contentToPost,
                                             response,
                                             headerName1, headerValue1,
                                             [headerName2, headerValue2...] )
                                    

                                    Nur mal so als Double-Check: @haus-automatisierung Kannst Du das ausschließen?

                                    1 Antwort Letzte Antwort
                                    0
                                    • K Offline
                                      K Offline
                                      kptkip
                                      schrieb am zuletzt editiert von kptkip
                                      #56

                                      Ich glaube, ich habe eine andere Vermutung:

                                      Der Rückgabewert des ersten Befehls ist ein JSON-Objekt

                                      javascript.0	13:37:00.168	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"token":"SuperToken"}
                                      

                                      Der zweite Befehl will aber als Auth-Token einen String. Da aber ein JSON-Objekt ankommt, schlägt die Authentifizierung fehl.

                                      Ich hab das Rauslösen des Wertes aus dem Object aber nicht hinbekommen (wurde im alten Script mit var TokenFromLogin = body.token;erledigt).
                                      Vielleicht kann mir da jemand mit mehr JS-Erfahrung auf die Sprünge helfen? :-)

                                      mcm1957M T 2 Antworten Letzte Antwort
                                      0
                                      • K kptkip

                                        Ich glaube, ich habe eine andere Vermutung:

                                        Der Rückgabewert des ersten Befehls ist ein JSON-Objekt

                                        javascript.0	13:37:00.168	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"token":"SuperToken"}
                                        

                                        Der zweite Befehl will aber als Auth-Token einen String. Da aber ein JSON-Objekt ankommt, schlägt die Authentifizierung fehl.

                                        Ich hab das Rauslösen des Wertes aus dem Object aber nicht hinbekommen (wurde im alten Script mit var TokenFromLogin = body.token;erledigt).
                                        Vielleicht kann mir da jemand mit mehr JS-Erfahrung auf die Sprünge helfen? :-)

                                        mcm1957M Online
                                        mcm1957M Online
                                        mcm1957
                                        schrieb am zuletzt editiert von Homoran
                                        #57

                                        @kptkip said in Plötzlich ReferenceError: request is not defined:

                                        Ich glaube, ich habe eine andere Vermutung:

                                        Der Rückgabewert des ersten Befehls ist ein JSON-Objekt

                                        javascript.0	13:37:00.168	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"token":"gibbetnichmehr"}
                                        

                                        Der zweite Befehl will aber als Auth-Token einen String. Da aber ein JSON-Objekt ankommt, schlägt die Authentifizierung fehl.

                                        Ich hab das Rauslösen des Wertes aus dem Object aber nicht hinbekommen (wurde im alten Script mit var TokenFromLogin = body.token;erledigt).
                                        Vielleicht kann mir da jemand mit mehr JS-Erfahrung auf die Sprünge helfen? :-)

                                        @kptkip
                                        Falls das Token nicht nur kurzzeitig gültig ist solltest du es hier löschen um Missbrauch zu minimieren.

                                        Entwicklung u Betreuung: envertech-pv, hoymiles-ms, ns-client, pid, snmp Adapter;
                                        Support Repositoryverwaltung.

                                        Wer Danke sagen will, kann nen Kaffee spendieren: https://paypal.me/mcm1957atiobroker

                                        LESEN - gute Forenbeitrage

                                        T K 2 Antworten Letzte Antwort
                                        0
                                        • mcm1957M mcm1957

                                          @kptkip said in Plötzlich ReferenceError: request is not defined:

                                          Ich glaube, ich habe eine andere Vermutung:

                                          Der Rückgabewert des ersten Befehls ist ein JSON-Objekt

                                          javascript.0	13:37:00.168	info	script.js.Strom_und_PV.Tibber_Polestar_SOC: {"token":"gibbetnichmehr"}
                                          

                                          Der zweite Befehl will aber als Auth-Token einen String. Da aber ein JSON-Objekt ankommt, schlägt die Authentifizierung fehl.

                                          Ich hab das Rauslösen des Wertes aus dem Object aber nicht hinbekommen (wurde im alten Script mit var TokenFromLogin = body.token;erledigt).
                                          Vielleicht kann mir da jemand mit mehr JS-Erfahrung auf die Sprünge helfen? :-)

                                          @kptkip
                                          Falls das Token nicht nur kurzzeitig gültig ist solltest du es hier löschen um Missbrauch zu minimieren.

                                          T Offline
                                          T Offline
                                          TT-Tom
                                          schrieb am zuletzt editiert von
                                          #58

                                          @mcm1957 dann lösche ihn auch in deinem Zitat ;)

                                          Gruß Tom
                                          https://github.com/tt-tom17
                                          Wenn meine Hilfe erfolgreich war, benutze bitte das Voting unten rechts im Beitrag

                                          NSPanel Script Wiki
                                          https://github.com/joBr99/nspanel-lovelace-ui/wiki

                                          NSPanel Adapter Wiki
                                          https://github.com/ticaki/ioBroker.nspanel-lovelace-ui/wiki

                                          HomoranH 1 Antwort Letzte Antwort
                                          0
                                          Antworten
                                          • In einem neuen Thema antworten
                                          Anmelden zum Antworten
                                          • Älteste zuerst
                                          • Neuste zuerst
                                          • Meiste Stimmen


                                          Support us

                                          ioBroker
                                          Community Adapters
                                          Donate

                                          863

                                          Online

                                          32.4k

                                          Benutzer

                                          81.5k

                                          Themen

                                          1.3m

                                          Beiträge
                                          Community
                                          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
                                          ioBroker Community 2014-2025
                                          logo
                                          • Anmelden

                                          • Du hast noch kein Konto? Registrieren

                                          • Anmelden oder registrieren, um zu suchen
                                          • Erster Beitrag
                                            Letzter Beitrag
                                          0
                                          • Home
                                          • Aktuell
                                          • Tags
                                          • Ungelesen 0
                                          • Kategorien
                                          • Unreplied
                                          • Beliebt
                                          • GitHub
                                          • Docu
                                          • Hilfe