Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [gelöst] HTTPS Request mit node-fetch

    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

    [gelöst] HTTPS Request mit node-fetch

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

      Hallo zusammen,

      meine fähikeiten mit Javascripts sind sehr begrenzt, trotzdem würde ich gerne ein HTTPS Request mit node-fetch realisieren.

      Ich möchte gerne Daten die von einem Dienstleister zu Verfügung gestellt werden abrufen. Dieser hat mit ein Skript fertig zu Verfügung gestellt welches ich auch schon eingebunden habe. Das funktioniert auch ohne Probleme, nur das empfangende Json bekomme ich nur im Log angezeigt. Um das weiter zu bearbeiten brauche ich das JSON im "ioBroker". Kann mir einer einen tip geben wie ich das JASON nach " 0_userdata.0.GridX_Daten.jsonDaten" bekomme.

      const { default: fetch }=require("node-fetch");
      
      
      
      const options = {
        method: 'GET',
        headers: {
          accept: 'application/vnd.gridx.v2020.11.09+json',
          authorization: 'XXXXXXXXXXXXX'
        }
      };
      
      fetch('https://api.gridx.de/clusters/XXXXXXXXXX/appliances/XXXXXXXXXX/constraints?order_by=priority&limit=1', options)
        .then(response => response.json()))
        .then(response => console.log(response))
        .catch(err => console.error(err));
      
      mickym 1 Reply Last reply Reply Quote 0
      • mickym
        mickym Most Active @Profoxion last edited by mickym

        @profoxion in dem Du in Zeile 15, hinter dem Pfeil statt console.log(response), den response stringifiziert in deinen Datenpunkt schreibst. setState(id, JSON.stringify(response)). Du musst halt die Syntax von setState nachschlagen und statt Id den Pfad zum Darenpunkt angeben.

        Also Zeile 15

        .then(response => console.log(response))
        

        In

        .then(response => setState(" 0_userdata.0.GridX_Daten.jsonDaten" , JSON.stringify(response))
        
        P 1 Reply Last reply Reply Quote 0
        • P
          Profoxion @mickym last edited by Profoxion

          @mickym

          Danke für deine Hilfe

          Funktioniert

          const { default: fetch }=require("node-fetch");
          
          const options = {
            method: 'GET',
            headers: {
              accept: 'application/vnd.gridx.v2020.11.09+json',
              authorization: 'tokenXXXXXXXXX'
            }
          };
          
          fetch('https://api.gridx.de/clusters/XXXXXXX/appliances/XXXXXXXXXXX/constraints?order_by=priority&limit=1', options)
            .then(response => response.json())
            .then(response => setState('0_userdata.0.GridX_Daten.jsonDaten',JSON.stringify(response),true))
             
            .catch(err => console.error(err));
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Support us

          ioBroker
          Community Adapters
          Donate

          911
          Online

          31.8k
          Users

          80.0k
          Topics

          1.3m
          Posts

          2
          3
          200
          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