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 Gardena API

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Hilfe bei Gardena API

    This topic has been deleted. Only users with topic management privileges can see it.
    • dslraser
      dslraser Forum Testing Most Active @Jey Cee last edited by dslraser

      @Jey-Cee sagte in Hilfe bei Gardena API:

      welche Fehler?

      javascript.0	2020-01-11 23:32:22.052	error	(377) at Script.runInContext (vm.js:133:20)
      javascript.0	2020-01-11 23:32:22.052	error	(377) at script.js.09_Unifi.Gardena:2:29
      javascript.0	2020-01-11 23:32:22.052	error	(377) TypeError: Cannot destructure property `URLSearchParams` of 'undefined' or 'null'.
      javascript.0	2020-01-11 23:32:22.052	error	(377) ^
      javascript.0	2020-01-11 23:32:22.052	error	(377) const { URLSearchParams } = require('url');
      javascript.0	2020-01-11 23:32:22.051	error	(377) script.js.09_Unifi.Gardena: script.js.09_Unifi.Gardena:2
      javascript.0	2020-01-11 23:32:22.051	error	(377) at Script.runInContext (vm.js:133:20)
      javascript.0	2020-01-11 23:32:22.050	error	(377) at script.js.09_Unifi.Gardena:2:29
      javascript.0	2020-01-11 23:32:22.050	error	(377) script.js.09_Unifi.Gardena: Error: Cannot find module '/opt/iobroker/node_modules/iobroker.javascript/lib/../../url'
      
      J.A.R.V.I.S. 1 Reply Last reply Reply Quote 0
      • J.A.R.V.I.S.
        J.A.R.V.I.S. Developer @dslraser last edited by

        @dslraser hast du das benötigte Modul im Javascript Adapter hinterlegt?

        dslraser 1 Reply Last reply Reply Quote 0
        • dslraser
          dslraser Forum Testing Most Active @J.A.R.V.I.S. last edited by

          @J-A-R-V-I-S

          Diese Module habe ich im Javascript Adapter

          Bildschirmfoto 2020-01-11 um 23.33.33.png

          J.A.R.V.I.S. 1 Reply Last reply Reply Quote 0
          • J.A.R.V.I.S.
            J.A.R.V.I.S. Developer @dslraser last edited by

            @dslraser dann fehlt dort das 'url' Modul.

            dslraser 1 Reply Last reply Reply Quote 0
            • dslraser
              dslraser Forum Testing Most Active @J.A.R.V.I.S. last edited by

              @J-A-R-V-I-S
              okay, jetzt kommt schon mal kein Fehler mehr. Wie kann ich jetzt Daten abrufen ?
              Dabei brauche ich Hilfe.

              J.A.R.V.I.S. Jey Cee 2 Replies Last reply Reply Quote 0
              • J.A.R.V.I.S.
                J.A.R.V.I.S. Developer @dslraser last edited by

                @dslraser welche möchtest du denn abrufen?

                dslraser 1 Reply Last reply Reply Quote 0
                • Jey Cee
                  Jey Cee Developer @dslraser last edited by

                  @dslraser du musst die Funktion login Ausführen:

                  let token = login();
                  

                  So bekommst du den Token in deine Variable.

                  1 Reply Last reply Reply Quote 0
                  • dslraser
                    dslraser Forum Testing Most Active @J.A.R.V.I.S. last edited by dslraser

                    @J-A-R-V-I-S
                    im Grund die von meinem Gateway bzw. vom Irrigation Control zur Bewässerung.

                    https://developer.1689.cloud/apis/GARDENA+smart+system+API#/readme

                    J.A.R.V.I.S. 1 Reply Last reply Reply Quote 0
                    • J.A.R.V.I.S.
                      J.A.R.V.I.S. Developer @dslraser last edited by J.A.R.V.I.S.

                      @dslraser dann versuch mal folgendes mit deinen Daten.

                      const request = require('request');
                      
                      function requestLocations(token, key) {
                          const options = {
                              url: 'https://api.smart.gardena.dev/v1/locations',
                              method: 'GET',
                              headers: {
                                  'Authorization': 'Bearer ' + token,
                                  'Authorization-Provider': 'husqvarna',
                                  'X-Api-Key': key
                              }
                          }
                      
                          request(options, (error, response, body) => {
                              console.log(body);
                          });
                      }
                      
                      dslraser 1 Reply Last reply Reply Quote 0
                      • dslraser
                        dslraser Forum Testing Most Active @J.A.R.V.I.S. last edited by

                        @J-A-R-V-I-S
                        Das ist die andere Methode, oder ?

                        J.A.R.V.I.S. Jey Cee 2 Replies Last reply Reply Quote 0
                        • J.A.R.V.I.S.
                          J.A.R.V.I.S. Developer @dslraser last edited by J.A.R.V.I.S.

                          @dslraser das wäre das Abfragen der Locations. Du kannst da natürlich auch eine Funktion draus machen. Habe es oben geändert.

                          1 Reply Last reply Reply Quote 0
                          • Jey Cee
                            Jey Cee Developer @dslraser last edited by

                            @dslraser Die erste API ist für die Anmeldung, die Zweite zur Steuerung der Gardena Geräte. Du brauchst also beides.
                            In Zeile 8 muss der Token aus Skript eins rein.

                            dslraser 1 Reply Last reply Reply Quote 0
                            • dslraser
                              dslraser Forum Testing Most Active @Jey Cee last edited by dslraser

                              @Jey-Cee sagte in Hilfe bei Gardena API:

                              In Zeile 8 muss der Token aus Skript eins rein.

                              Den habe ich noch nicht und auch noch nicht genau verstanden wie ich den ins Log oder in eine Variable bekomme.

                              J.A.R.V.I.S. 1 Reply Last reply Reply Quote 0
                              • J.A.R.V.I.S.
                                J.A.R.V.I.S. Developer @dslraser last edited by J.A.R.V.I.S.

                                @dslraser

                                @Jey-Cee sagte in Hilfe bei Gardena API:

                                let token = login();

                                Damit bekommst du den Token. Und dann rufst du die zweite Funktion auf.

                                requestLocations(token, appKey);
                                

                                Meine Funktion ist ungetestet, da ich dort keine Zugangsdaten habe. Laut der Doku sollte die Abfrage aber so vonstattengehen.

                                dslraser 1 Reply Last reply Reply Quote 0
                                • dslraser
                                  dslraser Forum Testing Most Active @J.A.R.V.I.S. last edited by

                                  @J-A-R-V-I-S
                                  @Jey-Cee

                                  So ?

                                  const fetch = require('node-fetch');
                                  const { URLSearchParams } = require('url');
                                  
                                  const username = 'xxx@xxx.de';
                                  const password = 'xxxxx';
                                  const appKey   = 'xxxxx';
                                  
                                  async function login() {
                                    const params = new URLSearchParams();
                                    params.set('grant_type', 'password');
                                    params.set('client_id', appKey);
                                    params.set('username', username);
                                    params.set('password', password);
                                  
                                    const res = await fetch('https://api.authentication.husqvarnagroup.dev/v1/oauth2/token', { 
                                      method: 'POST',
                                      body: params
                                    });
                                  
                                    if (!res.ok) {
                                      throw new Error(res.statusText);
                                    }
                                  
                                    return res.json();
                                  }
                                  let token = login();
                                  
                                  const request = require('request');
                                   
                                  function requestLocations(token, key) {
                                      const options = {
                                          url: 'https://api.smart.gardena.dev/v1/locations',
                                          method: 'GET',
                                          headers: {
                                              'Authorization': 'Bearer ' + token,
                                              'Authorization-Provider': 'husqvarna',
                                              'X-Api-Key': '6dc5b7d9-d426-4b58-84c8-c3733e08e9cb'
                                          }
                                      }
                                   
                                      request(options, (error, response, body) => {
                                          console.log(body);
                                      });
                                  }
                                  
                                  
                                  J.A.R.V.I.S. 1 Reply Last reply Reply Quote 0
                                  • J.A.R.V.I.S.
                                    J.A.R.V.I.S. Developer @dslraser last edited by

                                    @dslraser

                                    const fetch = require('node-fetch');
                                    const { URLSearchParams } = require('url');
                                    const request = require('request');
                                    
                                    const username = 'xxx@xxx.de';
                                    const password = 'xxxxx';
                                    const appKey   = 'xxxxx';
                                    
                                    async function login() {
                                    
                                        const params = new URLSearchParams();
                                        params.set('grant_type', 'password');
                                        params.set('client_id', appKey);
                                        params.set('username', username);
                                        params.set('password', password);
                                    
                                        const res = await fetch('https://api.authentication.husqvarnagroup.dev/v1/oauth2/token', { 
                                            method: 'POST',
                                            body: params
                                        });
                                    
                                        if (!res.ok) {
                                            throw new Error(res.statusText);
                                        }
                                    
                                        return res.json();
                                    }
                                    
                                    function requestLocations(token, key) {
                                        const options = {
                                            url: 'https://api.smart.gardena.dev/v1/locations',
                                            method: 'GET',
                                            headers: {
                                                'Authorization': 'Bearer ' + token,
                                                'Authorization-Provider': 'husqvarna',
                                                'X-Api-Key': '6dc5b7d9-d426-4b58-84c8-c3733e08e9cb'
                                            }
                                        }
                                     
                                        request(options, (error, response, body) => {
                                            console.log(body);
                                        });
                                    }
                                    
                                    let token = login();
                                    
                                    requestLocations(token, appKey);
                                    
                                    J.A.R.V.I.S. dslraser 2 Replies Last reply Reply Quote 0
                                    • J.A.R.V.I.S.
                                      J.A.R.V.I.S. Developer @J.A.R.V.I.S. last edited by

                                      bzw. unten anders, da das sonst asyncron ausgeführt wird und du keinen Token erhälst:

                                      let token = await login();
                                      
                                      requestLocations(token, appKey);
                                      

                                      das untere

                                      async function getData(appKey) {
                                          let token = await login();
                                      
                                          requestLocations(token, appKey);
                                      }
                                      
                                      getData(appKey);
                                      
                                      dslraser 1 Reply Last reply Reply Quote 0
                                      • dslraser
                                        dslraser Forum Testing Most Active @J.A.R.V.I.S. last edited by

                                        @J-A-R-V-I-S
                                        damit bekam ich

                                        {"message":"Forbidden"}
                                        
                                        1 Reply Last reply Reply Quote 0
                                        • dslraser
                                          dslraser Forum Testing Most Active @J.A.R.V.I.S. last edited by dslraser

                                          @J-A-R-V-I-S

                                          async function getData(appKey) {
                                              let token = await login();
                                           
                                              requestLocations(token, appKey);
                                          }
                                           
                                          getData(appKey);
                                          
                                          

                                          Damit habe ich nichts mehr im Log

                                          J.A.R.V.I.S. 1 Reply Last reply Reply Quote 0
                                          • J.A.R.V.I.S.
                                            J.A.R.V.I.S. Developer @dslraser last edited by J.A.R.V.I.S.

                                            @dslraser sagte in Hilfe bei Gardena API:

                                            async function getData(appKey) {

                                            dann bau mal bitte in dieser Funktion eine Consolenausgabe ein, die den Token ausgibt.

                                            console.log(token);
                                            

                                            und verwende sonst einmal in der anderen Ausgabe anstatt body response.

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            887
                                            Online

                                            31.6k
                                            Users

                                            79.5k
                                            Topics

                                            1.3m
                                            Posts

                                            javascript
                                            6
                                            59
                                            6694
                                            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