API keys for your systems
- An owner or admin creates a key in the portal under Developers, after choosing the organization at the top. The key looks like
hrx_live_…for real orders orhrx_test_…for the sandbox. - The key is shown once. We keep only a fingerprint, so copy it when it is made. A lost key is revoked and replaced.
- Send it on every call in the
Authorizationheader:Authorization: Bearer hrx_live_…. No cookie is needed. - Production calls go to
https://app-api.homelyrx.com; test keys and the test environment usehttps://stage-api.homelyrx.com. - A key works only in the organization it was made for and the clinics beneath it. Revoking it stops it at once.
curl https://app-api.homelyrx.com/v1/patients \
-H "Authorization: Bearer hrx_live_…"const res = await fetch('https://app-api.homelyrx.com/v1/patients', {
headers: { Authorization: `Bearer ${process.env.HRX_API_KEY}` },
});
console.log((await res.json()).meta.total);import os, requests
r = requests.get("https://app-api.homelyrx.com/v1/patients", headers={"Authorization": "Bearer " + os.environ["HRX_API_KEY"]})
print(r.json()["meta"]["total"])How sessions work
- Sign in with
POST /v1/auth/login. The reply sets a cookie namedhrx_session(the name can be changed in the API settings). - The cookie is
HttpOnlyandSameSite=Lax, so scripts on a web page cannot read it. It is markedSecureon production, so it travels over HTTPS only. - It is valid for 7 days by default. After that, or if the cookie is missing or invalid, calls return
401with the codeunauthenticatedand you sign in again. - Send the cookie on every call. curl does this with
-b cookies.txt, arequests.Sessiondoes it for you, and a browser does it when you setcredentials: 'include'.
Calling from a server
Node.js fetch does not keep cookies for you. Read the cookie from the sign-in reply and send it back on later calls.
const API = 'https://app-api.homelyrx.com';
const login = await fetch(`${API}/v1/auth/login`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ email: '[email protected]', password: 'your-password' }),
});
const cookie = login.headers.getSetCookie().map((c) => c.split(';')[0]).join('; ');
const res = await fetch(`${API}/v1/patients`, { headers: { cookie } });
console.log((await res.json()).meta.total);Roles and what they can do
Every person has one role. The role decides which writes are allowed; anyone signed in can read what their scope shows.
| Role | What it is for | Writes |
|---|---|---|
super_admin | HomelyRx staff who manage every organization and clinic. | Everything, including creating organizations and granting the permission to create them. |
owner | The person who runs an organization or clinic. | Patients, providers, orders, and creating clinics and (with permission) organizations. |
admin | A manager in an organization or clinic. | The same as an owner. |
staff | Day-to-day clinic users. | Create and edit patients, place orders and add order messages. Cannot delete patients, add providers or cancel orders. |
analyst | Read-only access for reporting. | None. Every write returns 403 with the code forbidden. |
Sign in
POST/v1/auth/login
Checks the email and password and starts a session. The same answer, invalidCredentials, is returned for an unknown email and a wrong password, so accounts cannot be guessed.
Who can call it
Anyone. No sign-in needed.
Request body
| Name | Type | Required | Description |
|---|---|---|---|
email | string | Required | The account email. Letters are compared in lower case. |
password | string | Required | The account password. |
Response
200 The person who signed in. The Set-Cookie header carries the session.
{
"data": {
"id": "6afe9b3c3a44248dcd845972",
"email": "[email protected]",
"name": "Rohit Suthar",
"role": "owner",
"clinicId": "6aeb0da3503a52507f605e76",
"canCreateOrganizations": false
}
}Errors
| Status | Code | When it happens |
|---|---|---|
| 400 | validation | The email is not a valid address or the password is empty. |
| 401 | invalidCredentials | The email or password is not right. |
| 403 | accountDisabled | The account has been disabled. Contact your clinic owner. |
Examples
curl -c cookies.txt -X POST "https://app-api.homelyrx.com/v1/auth/login" \
-H "content-type: application/json" \
-d '{"email":"[email protected]","password":"your-password"}'const API = 'https://app-api.homelyrx.com';
const res = await fetch(`${API}/v1/auth/login`, {
method: 'POST',
credentials: 'include',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ email: '[email protected]', password: 'your-password' }),
});
const { data: me } = await res.json();
console.log(me.role);import requests
api = "https://app-api.homelyrx.com"
s = requests.Session() # keeps the session cookie for the next calls
r = s.post(f"{api}/v1/auth/login", json={"email": "[email protected]", "password": "your-password"})
me = r.json()["data"]
print(me["role"])Read who you are
GET/v1/auth/me
Returns the signed-in person and the clinic or organization they belong to. Use it to check that a session is still valid.
Who can call it
Any signed-in role.
Response
200 The person and their home clinic or organization (clinic is null for a super admin).
{
"data": {
"id": "6afe9b3c3a44248dcd845972",
"email": "[email protected]",
"name": "Rohit Suthar",
"role": "owner",
"clinicId": "6aeb0da3503a52507f605e76",
"canCreateOrganizations": false,
"clinic": { "id": "6aeb0da3503a52507f605e76", "name": "HomelyMd", "city": "Tampa", "state": "FL" }
}
}Errors
| Status | Code | When it happens |
|---|---|---|
| 401 | unauthenticated | There is no session, or it has expired. |
Examples
curl -b cookies.txt "https://app-api.homelyrx.com/v1/auth/me"Sign out
POST/v1/auth/logout
Clears the session cookie. It works even when there is no session.
Who can call it
Anyone.
Response
204 No body. The cookie is cleared.
No body.
Examples
curl -b cookies.txt -c cookies.txt -X POST "https://app-api.homelyrx.com/v1/auth/logout"Register a clinic
POST/v1/auth/register
Creates a new clinic (waiting for approval) and its first owner, and signs that owner in. Use it for self-service sign-up. Staff who create clinics for other people use the clinics endpoints instead.
Who can call it
Anyone. No sign-in needed.
Request body
| Name | Type | Required | Description |
|---|---|---|---|
organization | string | Required | The name of the organization. At least 2 characters. |
clinicName | string | Required | The name of the clinic. At least 2 characters. |
firstName | string | Required | The owner's first name. |
lastName | string | Required | The owner's last name. |
email | string | Required | The owner's email. It becomes the sign-in name. |
password | string | Required | At least 12 characters. |
phone | string | Optional | A phone number. |
Response
201 The new owner. The Set-Cookie header carries the session.
{
"data": {
"id": "6b04310fcc8f4730ebbf8b01",
"email": "[email protected]",
"name": "Ana Silva",
"role": "owner",
"clinicId": "6b04310fcc8f4730ebbf8aff",
"canCreateOrganizations": false
}
}Errors
| Status | Code | When it happens |
|---|---|---|
| 400 | validation | A field is missing or invalid. For example the password is shorter than 12 characters. |
| 409 | emailTaken | An account with this email already exists. |
Examples
curl -c cookies.txt -X POST "https://app-api.homelyrx.com/v1/auth/register" \
-H "content-type: application/json" \
-d '{"organization":"New Clinic Group","clinicName":"New Clinic","firstName":"Ana","lastName":"Silva","email":"[email protected]","password":"a-long-password-123"}'