đŸ€–
Carnot
  • Carnot - Ă„bne data
  • API opbygning
  • Guides
    • FĂ„ adgang til API
    • Forbind til API
      • Python
      • JS/ TS
      • CURL
  • Data fundament
    • Energiproduktion og forbrug
    • Spotpriser
    • Opladningsplan
    • BilopsĂŠtning
  • Use Cases
    • For dem med elbil
    • For dem med home assistant
    • For dem med varmepumpe og buffertank
  • Extras
    • Keyboard Shortcuts
Powered by GitBook
On this page
  1. Guides
  2. Forbind til API

JS/ TS

// Eksempel pÄ integration i axios, NextJS-TS

import { useQuery } from "react-query";
import axios from "axios";

interface inputProps {
  daysahead: number;
  pricearea: string;
  energysource: string;
}

const getPrediction = async ({
  daysahead,
  energysource,
  pricearea,
}: inputProps) => {
  const { data } = await axios.get(
    `${process.env.NEXT_PUBLIC_API_BASE}/openapi/get_predict`,
    {
      params: {
        daysahead: daysahead,
        energysource: energysource,
        region: pricearea,
      },
      headers: {
        "apikey": `{{ api-key }}`,
        "username": `{{ username }}`,
      },
    }
  );

  return data;
};

function usePrediction({ daysahead, pricearea, energysource }: inputProps) {
  return useQuery(["prediction", pricearea, energysource, daysahead], () =>
    getPrediction({ daysahead, energysource, pricearea })
  );
}

export default usePrediction;
PreviousPythonNextCURL

Last updated 2 years ago