Sign-in and sign-up
Your app shows the screens and collects what the person types. The API checks it, creates the account when one is needed, and links the person to your key. The steps are the ones the Health Nexus site and app use themselves.
All of these endpoints take only your key (X-Api-Key, with the write scope). The email travels in the body.
Start with the email
Always begin with check-email.
curl -s "$HN_BASE/api/patient/partner/auth/check-email" \
-H "X-Api-Key: $HN_KEY" -H "Content-Type: application/json" \
-d '{"email":"jane@example.com"}'
outcome | Meaning | Next |
|---|---|---|
login | The person has an account and a password. | Sign in. |
setup | An account was created for the person and no password has been set. | The sign-up steps, sending action back at the end. |
register | The person is new. | The sign-up steps. |
For setup and register, the first verification code has already been emailed and the reply carries the verificationToken for the next step. When outcome is login and firstTime is true, nobody has signed in to this record yet: offer choose a password rather than a password box.
A new person gets a Health Nexus account. There is nothing to choose and nothing to set up on your side.
Sign in
curl -s "$HN_BASE/api/patient/partner/auth/sign-in" \
-H "X-Api-Key: $HN_KEY" -H "Content-Type: application/json" \
-d '{"email":"jane@example.com","password":"…"}'
There are two possible replies with HTTP 200, and one refusal. (The sandbox has a third: see the location step.)
Signed in. signedIn is true. You are done: see what a finished sign-in gives you.
A code is needed. The password was right, but the email or phone must be confirmed first.
{
"loginComplete": false,
"requiresVerification": true,
"verificationToken": "eyJhbGci…",
"verification": { "emailVerified": false, "emailSent": true, "phoneVerified": true, "phoneSent": false },
"account": { "accountId": 11 }
}
Collect the code and follow verification codes.
Wrong password. HTTP 401 with code: "wrong_password". After too many attempts for one email the API answers 429; see Limits.
Verification codes
verification tells you which code was sent. Call the matching endpoint with the token and the code the person typed:
curl -s "$HN_BASE/api/patient/partner/auth/sign-in/verify-email" \
-H "X-Api-Key: $HN_KEY" -H "Content-Type: application/json" \
-d '{"verificationToken":"eyJhbGci…","code":"482913","accountId":11}'
- If the sign-in reply had an
accountblock, send itsaccountIdwith each verify call. - When the code was the last thing missing, the reply is the finished sign-in.
- Otherwise the reply carries the next
verificationTokenand an updatedverification. Use verify-phone for the texted code. - resend-code sends the pending code again, once per cooldown.
Sign up
Each step returns the verificationToken for the next one.
- Email code. sign-up/verify-email with the token from check-email and the code the person received.
- Phone number. sign-up/phone with the mobile number and its dial code. A code is texted to it. country-codes lists the dial codes.
- Phone code. sign-up/verify-phone.
- Details and password. sign-up/complete.
curl -s "$HN_BASE/api/patient/partner/auth/sign-up/complete" \
-H "X-Api-Key: $HN_KEY" -H "Content-Type: application/json" \
-d '{
"verificationToken": "eyJhbGci…",
"action": "register_new_patient",
"firstName": "Jane", "lastName": "Doe",
"password": "Str0ng!Passw0rd",
"birthDate": "1990-01-31", "gender": "F", "zip": "94105",
"email": "jane@example.com"
}'
| Field | Rule |
|---|---|
action | The value check-email gave you: register_new_patient or register_existing_patient. |
password | At least 8 characters with upper case, lower case, a number and a special character. |
birthDate | A real YYYY-MM-DD date; age 16 to 100. |
gender | M or F. |
zip | For a new person. |
The reply is a finished sign-in: the person now has a Health Nexus account and is linked to your key. In the sandbox one more step comes first: see the location step.
If a code does not arrive, sign-up/resend-code sends it again.
The location step (sandbox)
In production a new sign-up lands in Health Nexus and is finished. The sandbox works differently: there a new sign-up, and the first sign-in after it, answers with one extra step before it is finished:
{ "success": true, "accountSelectionRequired": true, "identityToken": "eyJhbGci…", "person": { "firstName": "Jane", "lastName": "Doe", "email": "jane@example.com" } }
Get the list from locations and send any facilityID from it. Which one you pick does not matter in the sandbox:
curl -s "$HN_BASE/api/patient/partner/auth/select-location" \
-H "X-Api-Key: $HN_KEY" -H "Content-Type: application/json" \
-d '{"identityToken":"eyJhbGci…","facilityId":690,"email":"jane@example.com"}'
The reply is a finished sign-in.
You do not need a location screen for production. Keep the two calls in your code all the same, so that the reply is handled if it ever appears.
Forgotten password
- password-reset/start with the email. A code is emailed.
- password-reset/verify-email. If the reply says
verification.phoneSent: false, no text could be sent: ask for a number with password-reset/phone. - password-reset/verify-phone.
- password-reset/complete with the new password and the email. The person is signed in at once.
If check-email returned a preferred block, send its accountId in the body of every step of the reset.
Bot protection in production
In production, every step that makes Health Nexus send a code by email or text message is protected by Google reCAPTCHA. The person's device gets a token, your app passes it to your server, and your server forwards it on the call:
| Header | Send it on |
|---|---|
X-Recaptcha-Token | check-email, sign-up/start, sign-up/phone, sign-up/resend-code, sign-up/complete, sign-in/resend-code, password-reset/start, password-reset/phone, password-reset/resend-code |
X-Recaptcha-Token-Reset | password-reset/start, as a second token |
| Token for | reCAPTCHA v3 action |
|---|---|
| sign-up/complete | register |
| The second token of password-reset/start | reset_password |
| Every other step in the list | send_code |
- The reCAPTCHA site key comes with your production key, enabled for the web addresses and apps you name.
- A token works once and for two minutes. Get a new one right before each call; never store one.
- Without a valid token the step answers
403withcode: "captcha_failed". Nothing was sent. Get a fresh token and send the call again. - Sign-in with a password, the verify steps, locations and country codes need no token.
- The sandbox does not check tokens. You can build and test every flow there with server calls alone.
A finished sign-in
{
"success": true,
"signedIn": true,
"user": { "id": "665f1c…", "email": "jane@example.com", "name": "Jane Doe", "gender": "female", "accountId": 96 },
"terms": { "accepted": false, "acceptedAt": null, "url": "https://portal.health-nexus.com/terms" },
"link": { "partnerId": "your-partner-id", "created": true }
}
| Field | Use |
|---|---|
user.id | The person's Health Nexus id. Store it with your own user record. |
user.accountId | Send it as X-Subject-Account-Id on later calls. |
terms.accepted | When false, record the acceptance before reading data. |
link.created | true the first time this person signs in through you. |
No session token is returned. Your key and the person's email are the credential from here on, and the same person can sign in again at any time without creating a second link.