web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Calling external API i...
Power Apps
Answered

Calling external API in PCF

(0) ShareShare
ReportReport
Posted on by 26

Hello All,

 

I am trying to consume/fetch the data from external web api into PCF component. I am getting below error

"https.get is not a function". 

 

sthurangi_0-1669896074604.png

 

 private callHttps(url: string😞 Promise<any> {
        const https = require('https');

        return new Promise<string>(resolve => {
            https.get(url, (res: any) => {
                res.setEncoding("utf8");
                let body = "";
                res.on("data", (data: any) => {
                    body += data;
                });
                res.on("end", () => {
                    let respBody: any = JSON.parse(body);
                    resolve(respBody);
                });
            });
        });
    }

 

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    3,306 Most Valuable Professional on at

    Hello,

    I have never used this https package. Just a question - why regular fetch is not an option?

  • sthurangi Profile Picture
    26 on at

    Yes, it is an option tried using fetch even though it is showing "https.fetch" is not a function.

  • sthurangi Profile Picture
    26 on at

    Yes, it is an option tried using fetch even though it is showing "https.fetch" is not a function.

  • Verified answer
    Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    Hi @sthurangi , 

    I think @a33ik was recommending "fetch()", not http.fetch.

    Here are some docs: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

  • sthurangi Profile Picture
    26 on at

    Thanks @a33ik and @DianaBirkelbach 

    It's working

  • iwaldman Profile Picture
    159 on at

    I couldn't help myself 😀

     

    import * as React from 'react';
    import { Text } from '@fluentui/react/lib/Text';
    import { Spinner, SpinnerSize } from '@fluentui/react/lib/Spinner';
    
    const URL = 'https://pokeapi.co/api/v2/pokemon';
    
    interface Pokemons {
     count: number;
     next: string;
     previous?: any;
     results: {
     name: string;
     url: string;
     }[];
    }
    
    // Fetch a few Pokemons
    const getPokemons = async (): Promise<Pokemons> => {
     const response = await fetch(`${URL}?limit=20`);
     return await response.json();
    };
    
    export const PokemonList: React.FunctionComponent = () => {
     const [loading, setLoading] = React.useState(true);
     const [pokemons, setPokemons] = React.useState<Pokemons | null>();
    
     // Fetch a few Pokemons
     React.useEffect(() => {
     getPokemons().then((data) => {
     setPokemons(data);
     setLoading(false);
     });
     }, []);
    
     if (loading) {
     return <Spinner size={SpinnerSize.large} label="Loading Pokemons..." />;
     }
    
     return (
     <>
     {pokemons?.results.map((pokemon) => (
     <Text key={pokemon.name} variant="xLarge" style={{ color: 'purple' }} block>
     {pokemon.name}
     </Text>
     ))}
     </>
     );
    };
  • sthurangi Profile Picture
    26 on at

    Thanks @iwaldman 

    Got the response in the form of an array, would like to display the response to details list in pcf, how can I achieve this. without using out-of-box grid/datasets

    Any help will be appreciated

     

     

  • iwaldman Profile Picture
    159 on at

    You could try using the Fluent UI DetailsList react control.

     

    See https://developer.microsoft.com/en-us/fluentui#/controls/web/detailslist/basic for more information. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 914

#2
11manish Profile Picture

11manish 627

#3
Valantis Profile Picture

Valantis 598

Last 30 days Overall leaderboard