NEWS
Hilfe bei Gardena API
-
@dslraser dann fehlt dort das 'url' Modul.
@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
okay, jetzt kommt schon mal kein Fehler mehr. Wie kann ich jetzt Daten abrufen ?
Dabei brauche ich Hilfe. -
@J-A-R-V-I-S
okay, jetzt kommt schon mal kein Fehler mehr. Wie kann ich jetzt Daten abrufen ?
Dabei brauche ich Hilfe. -
@dslraser welche möchtest du denn abrufen?
@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
im Grund die von meinem Gateway bzw. vom Irrigation Control zur Bewässerung.https://developer.1689.cloud/apis/GARDENA+smart+system+API#/readme
@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 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); }); }@J-A-R-V-I-S
Das ist die andere Methode, oder ? -
@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.@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.
-
@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.
@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.
-
@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.
@J-A-R-V-I-S
@Jey-CeeSo ?
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
@Jey-CeeSo ?
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); }); }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); -
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);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); -
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
damit bekam ich{"message":"Forbidden"} -
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);@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
async function getData(appKey) { let token = await login(); requestLocations(token, appKey); } getData(appKey);Damit habe ich nichts mehr im Log
@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
bodyresponse. -
@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
bodyresponse.@J-A-R-V-I-S
kommt kein Token im Logconst fetch = require('node-fetch'); const { URLSearchParams } = require('url'); const request = require('request'); const username = 'xxx.xxx@xxx.de'; const password = 'xxx'; const appKey = 'xxx'; 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': 'xxx' } } request(options, (error, response, body) => { console.log(response); }); } async function getData(appKey) { let token = await login(); requestLocations(token, appKey); console.log(token); } getData(appKey); -
@dslraser probier einfach nur mal folgenden Code in einem eigenen Skrip aus:
const request = require('request'); const username = 'xxx@xxx.de'; const password = 'xxxxx'; const appKey = 'xxxxx'; const options = { url: 'https://api.authentication.husqvarnagroup.dev/v1/oauth2/token', method: 'POST', body: { grant_type: 'password', client_id: appKey, username: username, password: password } } request(options, (err, response, body) => { console.log(body); }); -
@dslraser probier einfach nur mal folgenden Code in einem eigenen Skrip aus:
const request = require('request'); const username = 'xxx@xxx.de'; const password = 'xxxxx'; const appKey = 'xxxxx'; const options = { url: 'https://api.authentication.husqvarnagroup.dev/v1/oauth2/token', method: 'POST', body: { grant_type: 'password', client_id: appKey, username: username, password: password } } request(options, (err, response, body) => { console.log(body); });@J-A-R-V-I-S
damit schmiert es direkt abhost.iobroker 2020-01-12 00:33:15.420 error Caught by controller[1]: (node:1118) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js proce host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[1]: (node:1118) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by r host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[1]: (node:1118) UnhandledPromiseRejectionWarning: TypeError: URLSearchParams is not a constructor host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[0]: at processImmediate (timers.js:658:5) host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[0]: at tryOnImmediate (timers.js:676:5) host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[0]: at runCallback (timers.js:705:18) host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[0]: at Immediate.<anonymous> (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:578:7) host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[0]: at end (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:549:18) host.iobroker 2020-01-12 00:33:15.419 error Caught by controller[0]: at Request.write (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:1500:27) host.iobroker 2020-01-12 00:33:15.419 error Caught by controller[0]: at ClientRequest.write (_http_outgoing.js:567:10) host.iobroker 2020-01-12 00:33:15.419 error Caught by controller[0]: at write_ (_http_outgoing.js:595:11) host.iobroker 2020-01-12 00:33:15.418 error Caught by controller[0]: TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string or Buffer. Received type object -
@J-A-R-V-I-S
damit schmiert es direkt abhost.iobroker 2020-01-12 00:33:15.420 error Caught by controller[1]: (node:1118) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js proce host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[1]: (node:1118) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by r host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[1]: (node:1118) UnhandledPromiseRejectionWarning: TypeError: URLSearchParams is not a constructor host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[0]: at processImmediate (timers.js:658:5) host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[0]: at tryOnImmediate (timers.js:676:5) host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[0]: at runCallback (timers.js:705:18) host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[0]: at Immediate.<anonymous> (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:578:7) host.iobroker 2020-01-12 00:33:15.420 error Caught by controller[0]: at end (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:549:18) host.iobroker 2020-01-12 00:33:15.419 error Caught by controller[0]: at Request.write (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:1500:27) host.iobroker 2020-01-12 00:33:15.419 error Caught by controller[0]: at ClientRequest.write (_http_outgoing.js:567:10) host.iobroker 2020-01-12 00:33:15.419 error Caught by controller[0]: at write_ (_http_outgoing.js:595:11) host.iobroker 2020-01-12 00:33:15.418 error Caught by controller[0]: TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string or Buffer. Received type object@dslraser habe es ausgebessert:
const request = require('request'); const username = 'xxx@xxx.de'; const password = 'xxxxx'; const appKey = 'xxxxx'; const options = { url: 'https://api.authentication.husqvarnagroup.dev/v1/oauth2/token', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: JSON.stringify({ grant_type: 'password', client_id: appKey, username: username, password: password }) } request(options, (err, response, body) => { console.log(body); });
Hey! Du scheinst an dieser Unterhaltung interessiert zu sein, hast aber noch kein Konto.
Hast du es satt, bei jedem Besuch durch die gleichen Beiträge zu scrollen? Wenn du dich für ein Konto anmeldest, kommst du immer genau dorthin zurück, wo du zuvor warst, und kannst dich über neue Antworten benachrichtigen lassen (entweder per E-Mail oder Push-Benachrichtigung). Du kannst auch Lesezeichen speichern und Beiträge positiv bewerten, um anderen Community-Mitgliedern deine Wertschätzung zu zeigen.
Mit deinem Input könnte dieser Beitrag noch besser werden 💗
Registrieren Anmelden