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.0on 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
- Create an onboarding with
POST /onboardings. - Create an embed session with
POST /onboardings/{hashid}/embed_sessions. Send the origin of your page asparent_origin, for examplehttps://partner.example.com. It must match the origin of one of your application's registered redirect URIs. - Put the returned
urlinto an iFrame. The URL works only once and only for 5 minutes, so create the embed session right before you show the iFrame. - 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.
- 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
sandboxattribute on the iFrame, allow at leastallow-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-Policyheader, usesame-origin-allow-popups, notsame-origin. Withsame-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.
| type | fields | when |
|---|---|---|
nexhealth.setup.ready | none | The iFrame loaded a page and can send events. It can come more than once. |
nexhealth.setup.step_changed | step, hashid | The practice moved to another setup step. The same step can come more than once. |
nexhealth.setup.resize | height | The height of the setup content changed, in pixels. Use it to set the height of the iFrame. |
nexhealth.setup.exit | none | The practice clicked the close button. Close the iFrame. |
nexhealth.setup.error | code | Setup cannot continue. See the codes below. |
nexhealth.setup.completed | hashid, subdomain, location_id, appointment_type_ids | Setup is done. The iFrame does not open the completion callback URL. |
Error codes
| code | meaning | what to do |
|---|---|---|
session_expired | The embed session or the onboarding has expired. | Create a new embed session. If the onboarding has expired, create a new onboarding first. |
steward_locked | Someone else at the practice already connected the EHR in this setup. | Close the iFrame. The page tells the practice who to contact. |
unexpected | Something 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>Updated about 23 hours ago