<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Making an API call within visual class. in Custom Visuals Development Discussion</title>
    <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Making-an-API-call-within-visual-class/m-p/3980786#M9888</link>
    <description>&lt;P&gt;Is it possible to make an API call using fetch in a custom visual.&lt;/P&gt;&lt;P&gt;I have set the privallages to allow web access to the API url and when I run the following function it succesfully prints the data in the console.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;private async getData() {
        try {
            const url: string = 'http://localhost:3000/api/routes'
            const response = await fetch(url)
            const data = await response.json();
            console.log(data);
            //return data;
        } catch (error) {
            console.log(error);
        }

    }&lt;/LI-CODE&gt;&lt;P&gt;The thing im struggling with is saving the returned data to a variable to use to create my visual.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to return the data to a variable in the constructor or update methods the variable is undefined or promise pending.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jun 2024 20:32:03 GMT</pubDate>
    <dc:creator>slinfoot</dc:creator>
    <dc:date>2024-06-07T20:32:03Z</dc:date>
    <item>
      <title>Making an API call within visual class.</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Making-an-API-call-within-visual-class/m-p/3980786#M9888</link>
      <description>&lt;P&gt;Is it possible to make an API call using fetch in a custom visual.&lt;/P&gt;&lt;P&gt;I have set the privallages to allow web access to the API url and when I run the following function it succesfully prints the data in the console.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;private async getData() {
        try {
            const url: string = 'http://localhost:3000/api/routes'
            const response = await fetch(url)
            const data = await response.json();
            console.log(data);
            //return data;
        } catch (error) {
            console.log(error);
        }

    }&lt;/LI-CODE&gt;&lt;P&gt;The thing im struggling with is saving the returned data to a variable to use to create my visual.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to return the data to a variable in the constructor or update methods the variable is undefined or promise pending.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2024 20:32:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Making-an-API-call-within-visual-class/m-p/3980786#M9888</guid>
      <dc:creator>slinfoot</dc:creator>
      <dc:date>2024-06-07T20:32:03Z</dc:date>
    </item>
  </channel>
</rss>

