The retool app using embed url does not work on self-hosted servers

Hi. I am Roy.

I have a problem.

We are running a retool server using the retool self-hosted method.
I used the Embed apps with Retool Embed feature.
(Embed apps with Retool Embed)

We created a webpage by inserting the retool embed url into login.html as an iframe.
The retool app in the iframe of login.html called the rest api 'login' defined in retool.
When I checked the docker log of the retool self-hosted server, the following error occurred.

{"level":"info","message":{"http":{"method":"POST","url_base":"https://retool.my-server.net","url_path":"/api/embedded/6182763e-1af8-11ee-bf0c-031f27f964cd/query?queryName=testApi"},"type":"REQUEST_BEGIN"},"pid":39,"requestId":"bfd39190-4edb-4ac1-9fdc-a72d0a302987","timestamp":"2023-07-14T02:18:08.548Z"}

{"level":"error","msg":"Cannot read properties of undefined (reading 'ensureOrganizationLoaded')","page":{"embed":true,"folderId":9,"name":"login","uuid":"6182763e-1af8-11ee-bf0c-031f27f964cd"},"pid":39,"requestId":"bfd39190-4edb-4ac1-9fdc-a72d0a302987","stack":"TypeError: Cannot read properties of undefined (reading 'ensureOrganizationLoaded')\n    at getPageSaveByReleaseVersionDelayedFetch (/snapshot/retool_development/backend/transpiled/server/modules/pageFetcher/index.js)\n    at getPageSaveByReleaseVersion (/snapshot/retool_development/backend/transpiled/server/modules/pageFetcher/index.js)\n    at /snapshot/retool_development/backend/transpiled/server/controllers/resources/index.js\n    at /snapshot/retool_development/backend/transpiled/common/utils.js\n    at dispatch (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:63:32)\n    at next (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:51:24)\n    at /snapshot/retool_development/backend/transpiled/common/utils.js\n    at /snapshot/retool_development/backend/transpiled/common/utils.js\n    at dispatch (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:63:32)\n    at next (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:51:24)\n    at convertSerializedUserParamsMiddleware (/snapshot/retool_development/backend/transpiled/common/middlewares/convertSerializedUserParamsMiddleware.js)\n    at /snapshot/retool_development/backend/transpiled/common/utils.js\n    at dispatch (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:63:32)\n    at next (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:51:24)\n    at getEmbeddedPageMiddleware (/snapshot/retool_development/backend/transpiled/server/controllers/embeddedPages.js)\n    at runMicrotasks (<anonymous>)","timestamp":"2023-07-14T02:18:08.585Z","type":"UNCAUGHT_ERROR"}

"Cannot read properties of undefined (reading 'ensureOrganizationLoaded')"

After applying the embed url to the iframe, the above error occurs when calling the API or accessing DB resources from the retool app.

What could have caused the error?

help plz.

I tried to make the above error log look better.

 {
  "level": "error",
  "msg": "Cannot read properties of undefined (reading 'ensureOrganizationLoaded')",
  "page": {
    "embed": true,
    "folderId": 9,
    "name": "login",
    "uuid": "6182763e-1af8-11ee-bf0c-031f27f964cd"
  },
  "pid": 40,
  "requestId": "dcd554ef-b0eb-4ac3-9abb-0822f227afc8",
  "stack": "TypeError: Cannot read properties of undefined (reading 'ensureOrganizationLoaded')\n    at getPageSaveByReleaseVersionDelayedFetch (/snapshot/retool_development/backend/transpiled/server/modules/pageFetcher/index.js)\n    at getPageSaveByReleaseVersion (/snapshot/retool_development/backend/transpiled/server/modules/pageFetcher/index.js)\n    at /snapshot/retool_development/backend/transpiled/server/controllers/resources/index.js\n    at /snapshot/retool_development/backend/transpiled/common/utils.js\n    at dispatch (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:63:32)\n    at next (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:51:24)\n    at /snapshot/retool_development/backend/transpiled/common/utils.js\n    at /snapshot/retool_development/backend/transpiled/common/utils.js\n    at dispatch (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:63:32)\n    at next (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:51:24)\n    at convertSerializedUserParamsMiddleware (/snapshot/retool_development/backend/transpiled/common/middlewares/convertSerializedUserParamsMiddleware.js)\n    at /snapshot/retool_development/backend/transpiled/common/utils.js\n    at dispatch (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:63:32)\n    at next (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:51:24)\n    at getEmbeddedPageMiddleware (/snapshot/retool_development/backend/transpiled/server/controllers/embeddedPages.js)\n    at runMicrotasks (<anonymous>)",
  "timestamp": "2023-07-18T10:00:05.643Z",
  "type": "UNCAUGHT_ERROR"
}
{
  "level": "error",
  "msg": "Internal server error: Cannot read properties of undefined (reading 'ensureOrganizationLoaded')",
  "page": {
    "embed": true,
    "folderId": 9,
    "name": "login",
    "uuid": "6182763e-1af8-11ee-bf0c-031f27f964cd"
  },
  "pid": 40,
  "requestId": "dcd554ef-b0eb-4ac3-9abb-0822f227afc8",
  "stack": "TypeError: Cannot read properties of undefined (reading 'ensureOrganizationLoaded')\n    at getPageSaveByReleaseVersionDelayedFetch (/snapshot/retool_development/backend/transpiled/server/modules/pageFetcher/index.js)\n    at getPageSaveByReleaseVersion (/snapshot/retool_development/backend/transpiled/server/modules/pageFetcher/index.js)\n    at /snapshot/retool_development/backend/transpiled/server/controllers/resources/index.js\n    at /snapshot/retool_development/backend/transpiled/common/utils.js\n    at dispatch (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:63:32)\n    at next (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:51:24)\n    at /snapshot/retool_development/backend/transpiled/common/utils.js\n    at /snapshot/retool_development/backend/transpiled/common/utils.js\n    at dispatch (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:63:32)\n    at next (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:51:24)\n    at convertSerializedUserParamsMiddleware (/snapshot/retool_development/backend/transpiled/common/middlewares/convertSerializedUserParamsMiddleware.js)\n    at /snapshot/retool_development/backend/transpiled/common/utils.js\n    at dispatch (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:63:32)\n    at next (/snapshot/retool_development/node_modules/compose-middleware/lib/index.js:51:24)\n    at getEmbeddedPageMiddleware (/snapshot/retool_development/backend/transpiled/server/controllers/embeddedPages.js)\n    at runMicrotasks (<anonymous>)",
  "timestamp": "2023-07-18T10:00:05.644Z",
  "type": "INTERNAL_ERROR"
}

Hi @Roy_Cho, happy to help with this!

For the app you are trying to access with Retool Embed - is this a public app? If so, that is probably the reason login would not work. Because public apps are accessible to anyone, login wouldn’t be useful nor is it likely to be supported here.

Let me know if that is the case. Otherwise, we can definitely dig deeper on this one.

1 Like

Hi @Chris_Cheasty , Thank you for your response.

I just want to render the embed url as an IFrame on my webpage and then make an api call to the retool resource when a button is clicked inside the IFrame.

Shouldn't this be possible?

I'll share with you the link to the webpage I created with the embed url.
https://youmeon-dev.stayge.net/login22.html

Thanks for the additional info. Generally speaking, yes - you should be able to make an API call by pressing a button within the Embed iFrame. However, to use resources within Retool Embed, users must have already been authenticated: https://docs.retool.com/docs/embed-apps-retool-embed.

If your embedded url links to a public retool app (a feature that has largely been replaced by Retool Portals and Retool Embed), then this would clash with the authorization requirements for Embed, since public retool apps can be shared with anyone and have no user authorization. Do you know if the app you are embedding is public?

1 Like

Yes. I want to allow users to access the retool admin public web page by authenticating with their own account system.

I found the cause of the problem.
I am happy to tell you this news.

It worked normally when I called without "releaseVersion" when requesting post for make to fetch the embed URL.

releaseVersion": "latest", => It's not work

But we need to use the "releaseVersion" field , so how?

Unfortunately, it looks like the feature you are trying to use is not supported with public apps.

I do see that you've been following along with our Embed documentation to get the basic functionality started - what if you tried testing your API call in Embed with a simple, non-public app first :face_with_monocle:? If you run into a similar problem, we could help you troubleshoot from there, since non-public apps are fully compatible with Embed.

Once that is working, you should be able to take full advantage of Embed using a non-public app that mimics your public one.

1 Like

Thanks @Chris_Cheasty.

Ok I see what you're saying.

For example, I want to use "v1.0.12" ( Live) in production mode and "v1.0.13" ( test ) in staging mode.

In staging mode I want to set "releaseVersion"="latest" and call it.
In production mode, I want "releaseVersion"=null and call it.

Because, This works well for non-public apps.
(query string => _releaseVersion=latest )

God bless Retool.
thanks.

Yup, all of that functionality should work for non-public apps :blush:

1 Like