Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
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);
                });
            });
        });
    }

 

  • iwaldman Profile Picture
    159 on at
    Re: Calling external API in PCF

    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. 

  • sthurangi Profile Picture
    26 on at
    Re: Calling external API in PCF

    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
    Re: Calling external API in PCF

    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
    Re: Calling external API in PCF

    Thanks @a33ik and @DianaBirkelbach 

    It's working

  • Verified answer
    Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at
    Re: Calling external API in PCF

    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
    Re: Calling external API in PCF

    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
    Re: Calling external API in PCF

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

  • Verified answer
    a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Calling external API in PCF

    Hello,

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

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 109 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 72 Super User 2025 Season 1

#3
mmbr1606 Profile Picture

mmbr1606 71 Super User 2025 Season 1

Overall leaderboard