Embedded setup

Show NexHealth setup inside an iFrame on your own page.

🚧

Embedded setup uses v3.1.0 endpoints. Send Nex-Api-Version: v3.1.0 on every request in this guide. It is still changing, and access is limited to approved partner institutions. Contact NexHealth before you build on it.

You can show NexHealth setup inside an iFrame on your own page. The practice stays on your page the whole time. The iFrame tells your page what happens through postMessage events.

How it works

  1. Create an onboarding with POST /onboardings.
  2. Create an embed session with POST /onboardings/{hashid}/embed_sessions. Send the origin of your page as parent_origin, for example https://partner.example.com. It must match the origin of one of your application's registered redirect URIs.
  3. Put the returned url into an iFrame. The URL works only once and only for 5 minutes, so create the embed session right before you show the iFrame.
  4. The practice signs in inside the iFrame. They can enter a code that we send to their email, or sign in with Google or Microsoft in a pop-up window. If the email already has a NexHealth account, they sign in to that account in a pop-up window. Your application never gets their session.
  5. Listen to the events below. When you get completed, setup is done and you can close the iFrame.

Create a new embed session each time you open the iFrame. Do not reuse a URL.

Requirements

  • Your page must use HTTPS.
  • Setup keeps its session in a partitioned cookie. It works in current Chrome and Firefox, and in Safari 26.2 and newer. Safari 18.5 to 26.1 cannot keep the session inside an iFrame.
  • If you use the sandbox attribute on the iFrame, allow at least allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox. Sign-in can open a pop-up window, and some links in setup open a new tab.
  • If the browser blocks the pop-up window, the iFrame asks the practice to allow pop-ups. It also offers another way to continue: a sign-in code, or setup in a new tab when the email already has a NexHealth account.
  • If your page sends a Cross-Origin-Opener-Policy header, use same-origin-allow-popups, not same-origin. With same-origin, the browser cuts the link between the iFrame and the pop-up window, so sign-in in the pop-up window cannot finish.

Events

Every event is an object with a type field. We send events only to the parent_origin of the embed session.

To get the events, listen for message events on the window of your page with window.addEventListener('message', ...). Check the origin of each message first, as described below. The example at the end of this page shows a full page that handles the events.

typefieldswhen
nexhealth.setup.readynoneThe iFrame loaded a page and can send events. It can come more than once.
nexhealth.setup.step_changedstep, hashidThe practice moved to another setup step. The same step can come more than once.
nexhealth.setup.resizeheightThe height of the setup content changed, in pixels. Use it to set the height of the iFrame.
nexhealth.setup.exitnoneThe practice clicked the close button. Close the iFrame.
nexhealth.setup.errorcodeSetup cannot continue. See the codes below.
nexhealth.setup.completedhashid, subdomain, location_id, appointment_type_idsSetup is done. The iFrame does not open the completion callback URL.

Error codes

codemeaningwhat to do
session_expiredThe embed session or the onboarding has expired.Create a new embed session. If the onboarding has expired, create a new onboarding first.
steward_lockedSomeone else at the practice already connected the EHR in this setup.Close the iFrame. The page tells the practice who to contact.
unexpectedSomething went wrong on our side.Close the iFrame and try again later.

If the embed session URL was already used or has expired, the iFrame shows an error page. It may send no events at all, because we cannot check which page opened the iFrame. If you do not get ready within a few seconds, create a new embed session.

Check the origin of every event

Your page can get messages from any window. Accept a message only when event.origin is the origin of the embed session url.

Example

<!DOCTYPE html>
<html>
<body>
  <button id="connect">Connect your practice</button>
  <iframe id="setup" hidden style="width: 530px; height: 700px; border: 0;"></iframe>

  <script>
    const frame = document.getElementById('setup')
    let setupOrigin = null

    document.getElementById('connect').addEventListener('click', async () => {
      // Your backend calls POST /onboardings/{hashid}/embed_sessions and returns the url.
      const response = await fetch('/your-backend/embed-session', { method: 'POST' })
      const { url } = await response.json()

      setupOrigin = new URL(url).origin
      frame.src = url
      frame.hidden = false
    })

    window.addEventListener('message', (event) => {
      if (event.origin !== setupOrigin || event.source !== frame.contentWindow) return

      const message = event.data
      switch (message.type) {
        case 'nexhealth.setup.resize':
          frame.style.height = `${message.height}px`
          break
        case 'nexhealth.setup.completed':
          console.log('Setup is done for location', message.location_id)
          frame.hidden = true
          break
        case 'nexhealth.setup.exit':
          frame.hidden = true
          break
        case 'nexhealth.setup.error':
          console.log('Setup cannot continue:', message.code)
          break
      }
    })
  </script>
</body>
</html>

Did this page help you?
ChangelogMCP serverErrorsdevelopers@nexhealth.com