Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. per script Rest anfrage senden

    NEWS

    • Amazon Alexa - ioBroker Skill läuft aus ?

    • Monatsrückblick – September 2025

    • Neues Video "KI im Smart Home" - ioBroker plus n8n

    per script Rest anfrage senden

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

      @delphinis
      Versuche es mal mit httpGet().

      D 1 Reply Last reply Reply Quote 1
      • D
        Delphinis @paul53 last edited by

        @paul53
        Das scheint offenbar auch zu funktionieren. Leider bekomme ich noch eine negative Antwort:

        error=getaddrinfo ENOTFOUND

        die URL ist wohl noch falsch. Ich komme aber mit der Doku irgendwie nicht klar. Muss mich da noch in die API reinstudieren.

        M 1 Reply Last reply Reply Quote 0
        • M
          MCU @Delphinis last edited by

          @delphinis Hab diesen Link gefunden

          https://data.geo.admin.ch/api/stac/v1/collections/ch.meteoschweiz.ogd-smn

          D 1 Reply Last reply Reply Quote 0
          • D
            Delphinis @MCU last edited by

            @mcu
            Ja, da war ich schon. Da findet sich auch der link
            https://data.geo.admin.ch/api/stac/v1/collections/ch.meteoschweiz.ogd-smn/items
            wo die Stationen aufgeführt sind. Aber ich weiss nicht, wie der Befehl aussehen muss, um die aktuellen Daten einer Station abrufen zu können. Die Doku ist für mich nicht verständlich. Aber das kommt sicher davon, dass ich mich mit diesem REST noch nicht auskenne. Bin noch am rechechieren.

            FernetMenta 1 Reply Last reply Reply Quote 0
            • FernetMenta
              FernetMenta Developer @Delphinis last edited by

              @delphinis https://data.geo.admin.ch/api/stac/static/spec/v0.9/api.html

              M 1 Reply Last reply Reply Quote 0
              • M
                MCU @FernetMenta last edited by MCU

                @fernetmenta

                httpGet('http://jsonplaceholder.typicode.com/posts', (err, response) => {
                    if (!err) {
                        console.log(response.statusCode);
                        console.log(response.data);
                    } else {
                        console.error(err);
                    }
                });
                

                Pass die url an und fertig

                Dann muss man evtl die Daten noch parsen

                let mydata = JSON.parse(response.data)
                console.log(mydata)
                

                Wenn du dein Programm angepasst hast dann kannst du zur Verfeinerung @paul53 fragen. Hab momentan kein System. Am Handy ist schlecht zu arbeiten.

                D 1 Reply Last reply Reply Quote 1
                • D
                  Delphinis @MCU last edited by Delphinis

                  @mcu
                  Prima, das funktioniert schon mal. Muss ich nur noch schauen, wie das mit dem header (If-None-Match)
                  funktioniert, und wie ich /collections und /items zusammenbasteln kann.
                  Edit: Da muss ich mich noch ein bisschen reindenken...

                  FernetMenta 1 Reply Last reply Reply Quote 0
                  • FernetMenta
                    FernetMenta Developer @Delphinis last edited by

                    @delphinis Ich würde dir axois empfehlen. Das git es auch für async und ist damit leichte handelbar. https://axios-http.com/docs/example
                    Dependency ist bereits in iob, kann also einfach mit require im Script verwendet werden.

                    D 1 Reply Last reply Reply Quote 0
                    • D
                      Delphinis @FernetMenta last edited by

                      @fernetmenta
                      ok, ich hab mal das erste einfache Beispiel genommen:

                      const axios = require('axios');
                      
                      // Make a request for a user with a given ID
                      axios.get('https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn/abo/ogd-smn_abo_t_now.csv')
                        .then(function (response) {
                          // handle success
                          console.log(response);
                        })
                        .catch(function (error) {
                          // handle error
                          console.log(error);
                        })
                        .finally(function () {
                          // always executed
                        });
                      

                      er meldet zwar einen Fehler bei

                      const axios = require('axios');
                      

                      Cannot find module 'axios' or its corresponding type declarations.

                      Aber das programm läuft und es liefert mir ein json, mit den Daten als csv. parsen kann ich dann selbst.
                      Aber ich weiss jetzt nicht, wo ich z.B. in den Header das "If-None-Match" eingeben kann, und wo ich collections und items definieren kann. Wird das in "paramters" gemacht (wie im zweiten Beispiel)?

                      FernetMenta 1 Reply Last reply Reply Quote 0
                      • FernetMenta
                        FernetMenta Developer @Delphinis last edited by FernetMenta

                        @delphinis

                        Headers kann man zu z.B. so setzen:

                        axios.get(URL, { headers: { Authorization: AuthStr } })
                        

                        Das findet man aber rellativ leicht raus, weil axios quasi der Standard ist für REST API in Node. httpGet hat, glaube ich, auch axois unter der Haube. Also ein zusätzlicher Wrapper. Kann in manchen Fällen gut sein. In diesem Fall aber m.E. nich tausreichen Dokumentiert.

                        1 Reply Last reply Reply Quote 1
                        • D
                          Delphinis last edited by

                          @fernetmenta said in per script Rest anfrage senden:

                          headers:

                          Danke erst mal. Ich muss mich da noch ein bisschen schlau machen. Jedenfalls kann ich jetzt schon ausprobieren.
                          Weisst du wieso es einen Fehler bei 'axios' anzeigt?

                          FernetMenta 1 Reply Last reply Reply Quote 0
                          • FernetMenta
                            FernetMenta Developer @Delphinis last edited by FernetMenta

                            @delphinis wie sieht der Fehler genau aus? Bei mit sieht das so aus und ich habe keinen Fehler:

                            const axios = require('axios');
                            
                            const apiurl_current = "https://api.openweathermap.org/data/2.5/weather?lat=xxx&lon=xxx&appid=xxx";
                            const apiurl_forecast = "https://api.openweathermap.org/data/2.5/forecast?lat=xxx&lon=xxx&appid=xxx";
                            
                            async function getWeatherData() {
                              let jsonData;
                              try {
                                let response = await axios.get(apiurl_current);
                                jsonData = await response.data;
                                setState("0_userdata.0.weather.current", JSON.stringify(jsonData), true);
                            
                                response = await axios.get(apiurl_forecast);
                                jsonData = await response.data;
                                setState("0_userdata.0.weather.forecast", JSON.stringify(jsonData), true);
                              } catch(error) {
                                console.error(error);
                              }
                            }
                            

                            Wie alt ist deine Installation. Scheint ein älteres "Problem" gewesen zu sein: https://forum.iobroker.net/topic/70578/gelöst-axios-hinzufügen-zu-script

                            D 1 Reply Last reply Reply Quote 0
                            • D
                              Delphinis @FernetMenta last edited by Delphinis

                              @fernetmenta
                              e78a067b-df54-4093-8156-302837f1f178-grafik.png
                              Ich hab das im Script-Adapter eingetragen:
                              0e566518-1c0a-4879-9227-7ea89c6d8996-grafik.png

                              FernetMenta 1 Reply Last reply Reply Quote 0
                              • FernetMenta
                                FernetMenta Developer @Delphinis last edited by

                                @delphinis Das sollte eigentich nicht notwendig sein. Steht bei mir auch nicht drin. Im Forum-Thread (siehe obe) wurde es anscheinend über ein Update von iob gelöst. Ist deine Version so alt? Der Thread ist ja schon von 2023.

                                Homoran 1 Reply Last reply Reply Quote 1
                                • Homoran
                                  Homoran Global Moderator Administrators @FernetMenta last edited by Homoran

                                  @fernetmenta sagte in per script Rest anfrage senden:

                                  Ist deine Version so alt?

                                  ich erinnere mich auch dass die Welle damals bei modulen, die bereits im iob js-adapter integriert sind und zusätzlich installiert wurden "grundlos" erschien.

                                  Der Eintrag von axios in der Instanz muss nicht sein.

                                  1 Reply Last reply Reply Quote 0
                                  • D
                                    Delphinis last edited by

                                    @homoran said in per script Rest anfrage senden:

                                    Der Eintrag von axios in der Instanz muss nicht sein.

                                    ok, dann nehm ich den wieder raus.
                                    Was heisst eigentlich "den iob updaten"? Ist das der Admin-Adapter? Der ist schon ein bisschen älter, aber ob der so alt ist weiss ich nicht:
                                    7.6.17
                                    aktuell 7.7.2

                                    Homoran FernetMenta 2 Replies Last reply Reply Quote 0
                                    • Homoran
                                      Homoran Global Moderator Administrators @Delphinis last edited by

                                      @delphinis zeig mal die Langfassung von iob diag

                                      D 1 Reply Last reply Reply Quote 0
                                      • D
                                        Delphinis @Homoran last edited by

                                        @homoran said in per script Rest anfrage senden:

                                        iob diag

                                        Sorry, soviel ich weiss geht iob diag auf windows nicht. Gibt es da was ähnliches?

                                        Homoran 1 Reply Last reply Reply Quote 0
                                        • FernetMenta
                                          FernetMenta Developer @Delphinis last edited by FernetMenta

                                          @delphinis

                                          aktuell 7.7.2

                                          Oh ja, dann scheint deine Nodejs-Version auch noch aus der Steinzeit zu sein. Ich habe 8.9.2 (Node v22).

                                          Die Leute sagen, dass sich das UI in den Versionen täuschen kann. Aber für einen ersten Anhaltpunkt tut es das. Hier unter Hosts:
                                          596924c9-778b-49c7-a16d-cc728707bd52-image.png

                                          D 1 Reply Last reply Reply Quote 0
                                          • D
                                            Delphinis @FernetMenta last edited by

                                            @fernetmenta
                                            0d1e1051-28cf-4761-9285-fbf328f02a8a-grafik.png

                                            D FernetMenta 2 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            1.1k
                                            Online

                                            32.3k
                                            Users

                                            81.1k
                                            Topics

                                            1.3m
                                            Posts

                                            6
                                            31
                                            583
                                            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