Can we call the web trigger URL from the Forge application itself?

Hi all,

I want to use a web trigger as a background task

My code

  const [url, setUrl] = useState(webTrigger.getUrl("example-web-trigger-key"))

  useEffect(() => {
    console.log("url", url);
    url && fetch(url)
      .then(() => console.log("fetched"))

I have a URL printed in logs, but the web trigger is not called… But it is possible to trigger it via the postman. Is this a known limitation?

Thanks in advance :slightly_smiling_face:

Hey @dhreshchuk! Thanks for reaching out!

Judging by the code that you’ve provided, I believe that you might be encountering a race condition. Because your are making a fetch call within useEffect without awaiting the response, the invocation to your app completes and the app invocation closes before the fetch resolves.

To solve this, you should be able to convert the useEffect callback to async and await the response of the fetch. See UI Kit useEffect.

However, I believe you might also find useful the Async Events API provided which might better suit your use-case. If this does not work or you have any follow up questions, feel free to reach out!

Hope this resolves things for you!

1 Like