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

Notifications

Announcements

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard