<?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 Re: Cutom widget to make https post request in Experience Builder Custom Widgets</title>
    <link>https://community.esri.com/t5/experience-builder-custom-widgets/cutom-widget-to-make-https-post-request/m-p/1392366#M246</link>
    <description>&lt;P&gt;Here is a working example of what I was saying. To use it you will need a free api key from&amp;nbsp;&lt;A href="https://developer.what3words.com/public-api" target="_self"&gt;What3Words.&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Mar 2024 06:41:40 GMT</pubDate>
    <dc:creator>PartyPelican</dc:creator>
    <dc:date>2024-03-07T06:41:40Z</dc:date>
    <item>
      <title>Cutom widget to make https post request</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/cutom-widget-to-make-https-post-request/m-p/1373960#M177</link>
      <description>&lt;P&gt;I've been tasked with finding a way to call a web api to pull a json response. The use would enter an address and an https post request would be made. The results would be displayed&amp;nbsp; and inserted into a feature layer.&lt;/P&gt;&lt;P&gt;Does anyone know of an example widget that makes this type of request?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2024 16:58:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/cutom-widget-to-make-https-post-request/m-p/1373960#M177</guid>
      <dc:creator>DavinShokes1</dc:creator>
      <dc:date>2024-01-24T16:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: Cutom widget to make https post request</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/cutom-widget-to-make-https-post-request/m-p/1391612#M244</link>
      <description>&lt;P&gt;Hi Davin, I am just starting to research this as well. Did you make any progress?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 02:24:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/cutom-widget-to-make-https-post-request/m-p/1391612#M244</guid>
      <dc:creator>GillPaterson</dc:creator>
      <dc:date>2024-03-06T02:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Cutom widget to make https post request</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/cutom-widget-to-make-https-post-request/m-p/1391681#M245</link>
      <description>&lt;P&gt;I dont know about a post request, but it would probably look similar to something like this get request. In this example, when the input is changed, a fetch request is made to the&amp;nbsp;&lt;A href="https://what3words.com/" target="_self"&gt;what3words api&lt;/A&gt;&amp;nbsp;and the results (the coordinates) are used to create an esri Point and its stored in state. Then the state (point coordinates) is displayed on the widget. Instead of displaying the results, you could use the esri js api to create geometry and add it to an existing layer or as a graphic to the map.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { React, jsx } from "jimu-core";
import { useState } from "react";
import Point from "@arcgis/core/geometry/Point";

export default function Widget(props) {
  const [point, setPoint] = useState(null);
  const [error, setError] = useState(null);

  function debounce(func, delay) {
    let timeoutId;
    return function (...args) {
      clearTimeout(timeoutId);
      timeoutId = setTimeout(() =&amp;gt; {
        func.apply(this, args);
      }, delay);
    };
  }

  const debouncedFetch = debounce((inputValue) =&amp;gt; {
    // Your fetch logic here
    fetch(
      "https://api.what3words.com/v3/convert-to-coordinates?words=filled.count.soap&amp;amp;key=YOUR_API_KEY"
    )
      .then((res) =&amp;gt; res.json())
      .then((data) =&amp;gt; {
        if (!data.coordinates) {
          setError("No coordinates found.");
        } else {
          setPoint(
            new Point({
              longitude: data.coordinates.lng,
              latitude: data.coordinates.lat,
            })
          );
        }
      })
      .catch((err) =&amp;gt; setError("Something went wrong."));
  }, 300); // 300 milliseconds delay

  return (
    &amp;lt;div className="bg-dark p-5"&amp;gt;
      &amp;lt;p className="text-light"&amp;gt;Fetching Widget&amp;lt;/p&amp;gt;
      &amp;lt;input
        type="text"
        placeholder="Enter 3 words"
        onChange={debouncedFetch}
      &amp;gt;&amp;lt;/input&amp;gt;
      &amp;lt;p className="text-light"&amp;gt;
        {point?.latitude}, {point?.longitude}
      &amp;lt;/p&amp;gt;
      &amp;lt;p className="text-light"&amp;gt;{error}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 07:14:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/cutom-widget-to-make-https-post-request/m-p/1391681#M245</guid>
      <dc:creator>PartyPelican</dc:creator>
      <dc:date>2024-03-06T07:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Cutom widget to make https post request</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/cutom-widget-to-make-https-post-request/m-p/1392366#M246</link>
      <description>&lt;P&gt;Here is a working example of what I was saying. To use it you will need a free api key from&amp;nbsp;&lt;A href="https://developer.what3words.com/public-api" target="_self"&gt;What3Words.&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 06:41:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/cutom-widget-to-make-https-post-request/m-p/1392366#M246</guid>
      <dc:creator>PartyPelican</dc:creator>
      <dc:date>2024-03-07T06:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Cutom widget to make https post request</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/cutom-widget-to-make-https-post-request/m-p/1398244#M258</link>
      <description>&lt;P&gt;Thanks so much for posting this example.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 02:15:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/cutom-widget-to-make-https-post-request/m-p/1398244#M258</guid>
      <dc:creator>GillPaterson</dc:creator>
      <dc:date>2024-03-20T02:15:06Z</dc:date>
    </item>
  </channel>
</rss>

