#How To Enable The 'fetch' function?

1 messages · Page 1 of 1 (latest)

daring island
#

I want to enable the fetch function in Appsmith because I have a psesific case of using appsmith apps inside an iframe.

My case:
I will run my apps inside an iframe of my authenticated page. Inside this page, I can do direct Rest API calls and get results, directly from the Client-Side (meaning that I can do a direct fetch('/rest/method'), and get data as response from the parent site (because the current user is already authenticated).

The parent site requires that I include a JS library to my Appsmith and I know how to do that, but now I need to be able to use the fetch directlly from my browser and not going back to the Appsmith server.

Thank you!

chilly totem
#

since v1.8.8 you can communicate between iframes and parent app with postWindowMessage("msgText", "Iframe1", "*"), so I'm thinking that you can ask the authenticated window to make those fetches client-side, and then that window will communicate the results using the same mechanism

#

look also into the iframe.onmessagereceived

#

bidirectional communication opens up new possibilities

daring island
#

Thanks for the hint! I'm afraid that this is not possible in my case.
The CRM platform works as the following:

  1. The app URL will be requested and displayed inside an Iframe in this CRM platform.
  2. Inside my app I need to load a JS library and it must be loaded as inside a <sciprt> tag inside the <head> and as soon as the page is loaded it will init a function to set the authentication. (I was able to do this part), But it looks like Appmisth is running all js inside an isolated container. If I try to run one of these lib functions, I get this error 'UncaughtPromiseRejection: BX24.selectUser is not a function', so the solution to this is more than just adding the lib into the header. The lib functions will do a fetch function on the client side of the app (not /execute/ api, so it won't happen in the backend of the server.

How can I do this in Appsmith?

I believe my challenge can be fixed by:
Allow the js functions to run outside the Appmsith container.

drifting axle
#

Hey @daring island we are currently working on adding support for custom JS libs directly inside appsmith and as part of it we will be adding fetch. I will ask someone from our team to expand on the details. Here's the issue to track - https://github.com/appsmithorg/appsmith/issues/2430

GitHub

Summary Import additional JS libraries that I can use. Creating this issue as a placeholder Support CDN based and JS SDK List of library support requested by users jsPDF https://www.npmjs.com/packa...

daring island
#

My question:
How can I add any missing JS function/feature that is not currently allowed in the Appsmith of my self-hosted instance?

drifting axle
#

Hey could you give an example of what is such a functionality?

daring island
#

so. I have a CRM that allows me to embed other Apps into its framework. These apps will be loaded inside an Iframe on this CRM.
These apps must load a JS SDK in order to interact with the CRM framework.

This SDK uses the fetch to communicate with the CRM from within the Iframe, meaning that I don't have to authenticate to call the RestAPI of the CRM because the SDK dose everything for me.

A page about the CRM <> app integration with the JS SDK:
https://training.bitrix24.com/rest_help/js_library/index.php

#

So the first way is to load the SDK and work with it.

The second approach is to use a simple fetch: so if I can use fetch, I can also contact the CRM directly and get a JSON response which I can use inside my app.

#

By this:
" I understand that ir runs it inside a promise container or something, that's amazing in many ways. "

I meant that even if I add JS SDK inside my appsmith <header> I won't be able to use it inside Appsmith.

This is why I want to know how to overwrite this because I won't use my apps just anywhere and the JS SDK is secure and reiable.

vapid tinsel
#

Enabling fetch is in its final stages. You can track the progress here.https://github.com/appsmithorg/appsmith/issues/16326
We are also working towards enabling import of custom JS libraries to be used within Appsmith apps.
If you interested in a preview of what we are building, check out http://3.6.94.31/applications (fetch is enabled in this preview)
The deploy preview is served over http and you might see some warnings. Sorry about that.

GitHub

Is there an existing issue for this? I have searched the existing issues Summary The API editor is awesome and a secure way to make requests when combined with a datasource. While it has its place,...