Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Hilfe bei der Script erstellung

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Hilfe bei der Script erstellung

    This topic has been deleted. Only users with topic management privileges can see it.
    • OliverIO
      OliverIO last edited by

      @t0bit3ch sagte in Hilfe bei der Script erstellung:

      127.0.0.1

      die verbindung wurde vom Rechner abgelehnt
      lustiger weise ist der rechner 127.0.0.1, was dein eigener ist.
      aus irgendeinem Grund wird die anfrage dorthin umgeleitet
      was läuft da auf dem rechner noch? pihole?

      1 Reply Last reply Reply Quote 0
      • OliverIO
        OliverIO last edited by

        @oliverio

        nimm mal bitte diese version:

        const axios = require('axios');
         
        function auth() {
        
            axios.post('https://api.emessage.de/auth/login',{
                username: 'username',
                password: 'password'
            },{
                headers: {
                    'Content-Type': 'application/json',
                }
            }).then(function (response) {
                console.log(response);
                if (response.status==200) {
                    var token = response.data.data.jwt;
                    sendMessage(token)
                }
            })
            .catch(function (error) {
                console.log(error);
            });
        }
         
        function sendMessage(token) {
            axios.post('https://api.emessage.de/api/eSendMessages',{
                "messageText": "Testnachricht",
                "recipients": [
                    {
                    "serviceName": "eCityruf",
                    "identifier": "Identifier 1"
                    }
                ]
            },{
                    headers: {
                        'Content-Type': 'text/plain',
                        'Authorization': token,
                    }
            })
            .then(function (response) {
                console.log(response);
            })
            .catch(function (error) {
                console.log(error);
            });
        }
        auth();
        

        wenn ich diese version verwende, dann funktioniert die abfrage.
        natürlich kommt dann die rückmeldung, das ich unauthorisiert bin.

        T T 2 Replies Last reply Reply Quote 1
        • T
          ticaki Developer @OliverIO last edited by

          @oliverio
          Danke für das Beispiel, btw. funktioniert die erste Version bei mir auch nicht Fehler 404 🙂

          1 Reply Last reply Reply Quote 0
          • T
            T0biT3ch @OliverIO last edited by

            @oliverio sagte in Hilfe bei der Script erstellung:

            @oliverio

            nimm mal bitte diese version:

            const axios = require('axios');
             
            function auth() {
            
                axios.post('https://api.emessage.de/auth/login',{
                    username: 'username',
                    password: 'password'
                },{
                    headers: {
                        'Content-Type': 'application/json',
                    }
                }).then(function (response) {
                    console.log(response);
                    if (response.status==200) {
                        var token = response.data.data.jwt;
                        sendMessage(token)
                    }
                })
                .catch(function (error) {
                    console.log(error);
                });
            }
             
            function sendMessage(token) {
                axios.post('https://api.emessage.de/api/eSendMessages',{
                    "messageText": "Testnachricht",
                    "recipients": [
                        {
                        "serviceName": "eCityruf",
                        "identifier": "Identifier 1"
                        }
                    ]
                },{
                        headers: {
                            'Content-Type': 'text/plain',
                            'Authorization': token,
                        }
                })
                .then(function (response) {
                    console.log(response);
                })
                .catch(function (error) {
                    console.log(error);
                });
            }
            auth();
            

            wenn ich diese version verwende, dann funktioniert die abfrage.
            natürlich kommt dann die rückmeldung, das ich unauthorisiert bin.

            Guten Abend,

            Ich habe das script grad nochmal mit meinen daten probiert. als info im log bekomme ich

            info	javascript.0 (31387) script.js.Pager_Alarmierung.emessage_Send_3: {}
            

            der pager wird aber leider nicht ausgelöst.
            könnte man die einzelnen schritte im script loggen um zu sehen woran es liegt?

            vielen vielen dank für die unterstützung 👍

            OliverIO 1 Reply Last reply Reply Quote 0
            • OliverIO
              OliverIO @T0biT3ch last edited by OliverIO

              @t0bit3ch sagte in Hilfe bei der Script erstellung:

              Zumindest das erste response objekt oder fehler objekt aus zeile 13 oder zeile 20 sollte ausgegeben werden.
              hast du oben rechts im skript debug und verbose eingeschaltet?

              ich habe hier mal noch ein paar verlaufsmeldungen eingefügt. die im unteren bereich sichtbar sein sollten

              
              const axios = require('axios');
               
              function auth() {
                  console.log("Start Auth");
                  axios.post('https://api.emessage.de/auth/login',{
                      username: 'username',
                      password: 'password'
                  },{
                      headers: {
                          'Content-Type': 'application/json',
                      }
                  }).then(function (response) {
                      console.log("Auth response");
                      console.log(response);
                      if (response.status==200) {
                          var token = response.data.data.jwt;
                          sendMessage(token)
                      }
                  })
                  .catch(function (error) {
                      console.log("Auth error");
                      console.log(error);
                  });
              }
               
              function sendMessage(token) {
                  console.log("sendmessage start");
                  axios.post('https://api.emessage.de/api/eSendMessages',{
                      "messageText": "Testnachricht",
                      "recipients": [
                          {
                          "serviceName": "eCityruf",
                          "identifier": "Identifier 1"
                          }
                      ]
                  },{
                          headers: {
                              'Content-Type': 'text/plain',
                              'Authorization': token,
                          }
                  })
                  .then(function (response) {
                      console.log("sendmessage respones");
                      console.log(response);
                  })
                  .catch(function (error) {
                      console.log("sendmessage error");
                      console.log(error);
                  });
              }
              auth();
              
              
              T T 2 Replies Last reply Reply Quote 0
              • T
                ticaki Developer @OliverIO last edited by ticaki

                @oliverio
                Bei mir aktuell und latest. Ergibt:

                    axios.get(slink)
                    .then(function(response){
                        console.log(response) // im log steht dann: warn	script.js.Messages.tankerkoenig: {}
                    })
                

                Ich gebe jetzt response.data im log aus um zu sehen was ankommt.
                EDIT:
                mit async await bekomme ich das:

                warn	script.js.common.UWZ: Converting circular structure to JSON --> starting at object with constructor 'ClientRequest' | property 'socket' -> object with constructor 'Socket' --- property '_httpMessage' closes the circle
                
                1 Reply Last reply Reply Quote 0
                • T
                  T0biT3ch @OliverIO last edited by T0biT3ch

                  @oliverio
                  ich habe debug und verbose eingeschaltet. wenn ich das script ausführe bekomme ich diese log

                  info	javascript.0 (31387) Start javascript script.js.Pager_Alarmierung.emessage_Send_3
                  20:21:59.200	info	javascript.0 (31387) script.js.Pager_Alarmierung.emessage_Send_3: Start Auth
                  20:21:59.200	info	javascript.0 (31387) script.js.Pager_Alarmierung.emessage_Send_3: registered 0 subscriptions and 0 schedules
                  20:21:59.392	info	javascript.0 (31387) script.js.Pager_Alarmierung.emessage_Send_3: Auth response
                  20:21:59.396	info	javascript.0 (31387) script.js.Pager_Alarmierung.emessage_Send_3: Auth error
                  20:21:59.396	info	javascript.0 (31387) script.js.Pager_Alarmierung.emessage_Send_3: {}
                  

                  pager bleibt weiterhin ruhig 😞

                  das ist der code aus dem programm postman mit dem die authentifizierung funktioniert

                  var axios = require('axios');
                  var data = JSON.stringify({
                    "username": "USERNAME",
                    "password": "PASSWORD"
                  });
                  
                  var config = {
                    method: 'post',
                    url: 'https://api.emessage.de/auth/login',
                    headers: { 
                      'Authorization': 'Basic Og==', 
                      'Content-Type': 'application/json'
                    },
                    data : data
                  };
                  
                  axios(config)
                  .then(function (response) {
                    console.log(JSON.stringify(response.data));
                  })
                  .catch(function (error) {
                    console.log(error);
                  });
                  

                  und mit diesem code aus postman kann ich den pager auslösen

                  var axios = require('axios');
                  var data = JSON.stringify({
                    "messageText": "Testnachricht",
                    "recipients": [
                      {
                        "serviceName": "eCityruf",
                        "identifier": "*********"
                      }
                    ]
                  });
                  
                  var config = {
                    method: 'post',
                    url: 'https://api.emessage.de/rs/eSendMessages',
                    headers: { 
                      'Authorization': 'Bearer jdfngjdfgnhflnhlhnjkgöfxclknjfgnklkmnvöldkgnbjhb önflgkdsnölkdymfkäsöldgn lkdnfgksdnfgnbksngjrfgblfdngfskdöngölnhdknhfäödlkgtekröälqenacklvnbmözlmvtöälaenrljeknvtbjölrnzrtmzövdrml.', 
                      'Content-Type': 'application/json'
                    },
                    data : data
                  };
                  
                  axios(config)
                  .then(function (response) {
                    console.log(JSON.stringify(response.data));
                  })
                  .catch(function (error) {
                    console.log(error);
                  });
                  
                  
                  OliverIO 1 Reply Last reply Reply Quote 0
                  • OliverIO
                    OliverIO @T0biT3ch last edited by

                    @t0bit3ch sagte in Hilfe bei der Script erstellung:

                    'Authorization': 'Basic Og==', 
                    

                    Der einzige Unterschied ist Zeile 11.
                    Das steht nicht im pdf Dokument drin
                    Du kannst ja diesen Header dem Code noch hinzufügen

                    1 Reply Last reply Reply Quote 0
                    • T
                      ticaki Developer last edited by ticaki

                      Werft die

                      console.log(response);
                      

                      Aufrufe alle raus. Hab oben geschrieben, dass es einen Fehler auslöst und dann wahrscheinlich in den .catch() Block springt. Log sieht zumindest danach aus.

                      T 1 Reply Last reply Reply Quote 0
                      • T
                        T0biT3ch @ticaki last edited by

                        @ticaki sagte in Hilfe bei der Script erstellung:

                        Werft die

                        console.log(response);
                        

                        Aufrufe alle raus. Hab oben geschrieben, dass es einen Fehler auslöst und dann wahrscheinlich in den .catch() Block springt. Log sieht zumindest danach aus.

                        habe jetzt den code um die zeile

                        'Authorization': 'Basic Og==',
                        

                        erweitert und die

                        console.log(response);
                        

                        entfernt. wenn ich den code jetzt ausführe bekomme ich folgende log

                        info	javascript.0 (31387) script.js.Pager_Alarmierung.emessage_Send_3: {'message':'Request failed with status code 401','name':'Error','stack':'Error: Request failed with status code 401\n at createError (/opt/iobroker/node_modules/iobroker.javascript/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/opt/iobroker/node_modules/iobroker.javascript/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/opt/iobroker/node_modules/iobroker.javascript/node_modules/axios/lib/adapters/http.js:260:11)\n at IncomingMessage.emit (events.js:326:22)\n at IncomingMessage.EventEmitter.emit (domain.js:483:12)\n at endReadableNT (_stream_readable.js:1241:12)\n at processTicksAndRejections (internal/process/task_queues.js:84:21)','config':{'url':'https://api.emessage.de/rs/eSendMessages','method':'post','data':'{\'messageText\':\'Testnachricht\',\'recipients\':[{\'serviceName\':\'eCityruf\',\'identifier\':\'*******\'}]}','headers':{'Content-Type':'text/plain','Authorization':'hgjfhglöfhdghdhugdfhgöksydjäfgposjghifhgjofnbvdjkidsigfhfdoghfoihgsdihgfiohgodhgosihfghogfdhgoiuhfgosihgsdghesiujpojfpjurtzoieur984548ß90uitjkgigjhöohsdgpsio','User-Agent':'axios/0.21.1','Content-Length':96},'transformRequest':[null],'transformResponse':[null],'timeout':0,'xsrfCookieName':'XSRF-TOKEN','xsrfHeaderName':'X-XSRF-TOKEN','maxContentLength':-1,'maxBodyLength':-1}}
                        
                        T 1 Reply Last reply Reply Quote 0
                        • T
                          T0biT3ch @T0biT3ch last edited by

                          @t0bit3ch
                          muss beim token noch das 'Bearer' voran?

                          OliverIO 1 Reply Last reply Reply Quote 0
                          • OliverIO
                            OliverIO @T0biT3ch last edited by

                            @t0bit3ch
                            Ja, bearer muss noch davor.
                            Vergleiche die Notation mit dem pdf. Genau so muss es raus.
                            sonst sieht es schon mal gut aus. Die Abfragen sind raus gegangen.

                            T 1 Reply Last reply Reply Quote 0
                            • T
                              T0biT3ch @OliverIO last edited by

                              @oliverio
                              Wie muss ich es denn schreiben? Ich hatte schon ein paar Sachen probiert, aber leider ohne Erfolg

                              T 1 Reply Last reply Reply Quote 0
                              • T
                                ticaki Developer @T0biT3ch last edited by

                                @t0bit3ch
                                es müsste eigentlich so richtig sein:

                                   {
                                            headers: {
                                                'Content-Type': 'text/plain',
                                                'Authorization': 'Bearer ' + token,
                                            }
                                    })
                                
                                T 1 Reply Last reply Reply Quote 0
                                • T
                                  T0biT3ch @ticaki last edited by T0biT3ch

                                  @ticaki
                                  @OliverIO

                                  Guten morgen,

                                  ich habe bei den versuchen das Bearer in den code mit einzubauen das + vergessen 🤦

                                  'authorization': 'Bearer ' + token,
                                  

                                  ich habe den code jetzt so angepasst

                                  const axios = require('axios');
                                   
                                  function auth() {
                                   
                                      axios.post('https://api.emessage.de/auth/login',{
                                          username: 'USERNAME',
                                          password: 'PASSWORD'
                                      },{
                                          headers: {
                                              'Authorization': 'Basic Og==',
                                              'Content-Type': 'application/json',
                                          }
                                      }).then(function (response) {
                                          if (response.status==200) {
                                              var token = response.data.data.jwt;
                                              sendMessage(token)
                                          }
                                      })
                                      .catch(function (error) {
                                          console.log(error);
                                      });
                                      
                                  }
                                   
                                  function sendMessage(token) {
                                      axios.post('https://api.emessage.de/rs/eSendMessages',{
                                          "messageText": "Testnachricht",
                                          "recipients": [
                                              {
                                              "serviceName": "eCityruf",
                                              "identifier": "********"
                                              }
                                          ]
                                      },{
                                              headers: {
                                                  'Content-Type': 'text/plain',
                                                  'Authorization': 'Bearer ' + token,
                                              }
                                      
                                      })
                                      .catch(function (error) {
                                          console.log(error);
                                      });
                                   }
                                   
                                  auth();
                                  

                                  doch leider bekomme ich noch folgende log

                                  info	javascript.0 (31387) script.js.Pager_Alarmierung.emessage_Send_3: registered 0 subscriptions and 0 schedules
                                  
                                  info	javascript.0 (31387) script.js.Pager_Alarmierung.emessage_Send_3: {'message':'Request failed with status code 400','name':'Error','stack':'Error: Request failed with status code 400\n at createError (/opt/iobroker/node_modules/iobroker.javascript/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/opt/iobroker/node_modules/iobroker.javascript/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/opt/iobroker/node_modules/iobroker.javascript/node_modules/axios/lib/adapters/http.js:260:11)\n at IncomingMessage.emit (events.js:326:22)\n at IncomingMessage.EventEmitter.emit (domain.js:483:12)\n at endReadableNT (_stream_readable.js:1241:12)\n at processTicksAndRejections (internal/process/task_queues.js:84:21)','config':{'url':'https://api.emessage.de/rs/eSendMessages','method':'post','data':'{\'messageText\':\'Testnachricht\',\'recipients\':[{\'serviceName\':\'eCityruf\',\'identifier\':\'5201709\'}]}','headers':{'Content-Type':'text/plain','Authorization':'Bearer ighndoönhgdboknbgoföänkjhäpsofmjsponmgbpoikfgnbäkmövkömnfpidsahfiohgniocjro#eiutv0gßreitéß049u48w+9r5uiq0´rwjkefgirgjzh+09vujr5tßhbz iüjvpoawxkjxe2','User-Agent':'axios/0.21.1','Content-Length':96},'transformRequest':[null],'transformResponse':[null],'timeout':0,'xsrfCookieName':'XSRF-TOKEN','xsrfHeaderName':'X-XSRF-TOKEN','maxContentLength':-1,'maxBodyLength':-1}}
                                  

                                  und der pager bleibt auch ruhig.

                                  1 Reply Last reply Reply Quote 0
                                  • T
                                    ticaki Developer last edited by

                                    @t0bit3ch sagte in Hilfe bei der Script erstellung:

                                    axios.post('https://api.emessage.de/rs/eSendMessages',{

                                    In der PDF steht das die Adresse:

                                    axios.post('https://api.emessage.de/api/eSendMessages',{
                                    
                                    T 1 Reply Last reply Reply Quote 0
                                    • T
                                      T0biT3ch @ticaki last edited by

                                      @ticaki
                                      Das ist korrekt, funktioniert aber leider nicht. Wenn man sich in der PDF die Screenshots des Postman Programms anschaut sieht man die funktionierende Adresse. Hatte es im Script aber auch schon mit beiden probiert.

                                      OliverIO 1 Reply Last reply Reply Quote 0
                                      • OliverIO
                                        OliverIO @T0biT3ch last edited by

                                        @T0biT3ch
                                        Zeig nochmal die postman Informationen zum 2. request
                                        Der funktioniert hat

                                        T 1 Reply Last reply Reply Quote 0
                                        • T
                                          T0biT3ch @OliverIO last edited by

                                          @oliverio
                                          hier der code zum holen des token

                                          var axios = require('axios');
                                          var data = JSON.stringify({
                                            "username": "USERNAME",
                                            "password": "PASSWORD"
                                          });
                                          
                                          var config = {
                                            method: 'post',
                                            url: 'https://api.emessage.de/auth/login',
                                            headers: { 
                                              'Authorization': 'Basic Og==', 
                                              'Content-Type': 'application/json'
                                            },
                                            data : data
                                          };
                                          
                                          axios(config)
                                          .then(function (response) {
                                            console.log(JSON.stringify(response.data));
                                          })
                                          .catch(function (error) {
                                            console.log(error);
                                          });
                                          

                                          es scheint als würde dieser teil in deinem code funktionieren, da die log beim ausführen ja einen token ausgibt.

                                          und das ist der code zum senden der nachrichten

                                          var axios = require('axios');
                                          var data = JSON.stringify({
                                            "messageText": "Testnachricht",
                                            "recipients": [
                                              {
                                                "serviceName": "eCityruf",
                                                "identifier": "********"
                                              }
                                            ]
                                          });
                                          
                                          var config = {
                                            method: 'post',
                                            url: 'https://api.emessage.de/rs/eSendMessages',
                                            headers: { 
                                              'Authorization': 'Bearer hgöfhogsioghösibnovdjuös<opriheourhweidjmanspkf<gob vuodsöahgbfdosuib0dsifohw84u0ü93rhfouisjhbgnvsoifedsökgpfingüer4984utißqü+äowfmägjhipoqehwfüouasdhgousgjohugurhgjiwehfgiwhfwquhbdcasukojgbhikgögloadfjasfghitiu<fbghkjybgvidfgdhfhgkjhlkzthgtzjklioölzfkdtjrhgstgfzhjui.k,mnjhbgvfadeshgjm', 
                                              'Content-Type': 'application/json'
                                            },
                                            data : data
                                          };
                                          
                                          axios(config)
                                          .then(function (response) {
                                            console.log(JSON.stringify(response.data));
                                          })
                                          .catch(function (error) {
                                            console.log(error);
                                          });
                                          
                                          
                                          T 1 Reply Last reply Reply Quote 0
                                          • T
                                            ticaki Developer @T0biT3ch last edited by

                                            @t0bit3ch
                                            Content/Type ist anders

                                            T 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            903
                                            Online

                                            31.9k
                                            Users

                                            80.1k
                                            Topics

                                            1.3m
                                            Posts

                                            6
                                            98
                                            5424
                                            Loading More Posts
                                            • Oldest to Newest
                                            • Newest to Oldest
                                            • Most Votes
                                            Reply
                                            • Reply as topic
                                            Log in to reply
                                            Community
                                            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                            The ioBroker Community 2014-2023
                                            logo