Developer docs

Authentication

The API knows who is calling either from a session cookie (people signing in) or from an API key (your own systems). Use an API key for anything that runs without a person: it is made for one organization and works in it and everything beneath it.

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 or hrx_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 Authorization header: Authorization: Bearer hrx_live_…. No cookie is needed.
  • Production calls go to https://app-api.homelyrx.com; test keys and the test environment use https://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.
Call the API with a key
curl https://app-api.homelyrx.com/v1/patients \
  -H "Authorization: Bearer hrx_live_…"

How sessions work

  • Sign in with POST /v1/auth/login. The reply sets a cookie named hrx_session (the name can be changed in the API settings).
  • The cookie is HttpOnly and SameSite=Lax, so scripts on a web page cannot read it. It is marked Secure on 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 401 with the code unauthenticated and you sign in again.
  • Send the cookie on every call. curl does this with -b cookies.txt, a requests.Session does it for you, and a browser does it when you set credentials: '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.

Node.js
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.

Roles
RoleWhat it is forWrites
super_adminHomelyRx staff who manage every organization and clinic.Everything, including creating organizations and granting the permission to create them.
ownerThe person who runs an organization or clinic.Patients, providers, orders, and creating clinics and (with permission) organizations.
adminA manager in an organization or clinic.The same as an owner.
staffDay-to-day clinic users.Create and edit patients, place orders and add order messages. Cannot delete patients, add providers or cancel orders.
analystRead-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

NameTypeRequiredDescription
emailstringRequiredThe account email. Letters are compared in lower case.
passwordstringRequiredThe account password.

Response

200 The person who signed in. The Set-Cookie header carries the session.

Example response
{
  "data": {
    "id": "6afe9b3c3a44248dcd845972",
    "email": "[email protected]",
    "name": "Rohit Suthar",
    "role": "owner",
    "clinicId": "6aeb0da3503a52507f605e76",
    "canCreateOrganizations": false
  }
}

Errors

StatusCodeWhen it happens
400validationThe email is not a valid address or the password is empty.
401invalidCredentialsThe email or password is not right.
403accountDisabledThe 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"}'

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).

Example response
{
  "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

StatusCodeWhen it happens
401unauthenticatedThere is no session, or it has expired.

Examples

curl
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
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

NameTypeRequiredDescription
organizationstringRequiredThe name of the organization. At least 2 characters.
clinicNamestringRequiredThe name of the clinic. At least 2 characters.
firstNamestringRequiredThe owner's first name.
lastNamestringRequiredThe owner's last name.
emailstringRequiredThe owner's email. It becomes the sign-in name.
passwordstringRequiredAt least 12 characters.
phonestringOptionalA phone number.

Response

201 The new owner. The Set-Cookie header carries the session.

Example response
{
  "data": {
    "id": "6b04310fcc8f4730ebbf8b01",
    "email": "[email protected]",
    "name": "Ana Silva",
    "role": "owner",
    "clinicId": "6b04310fcc8f4730ebbf8aff",
    "canCreateOrganizations": false
  }
}

Errors

StatusCodeWhen it happens
400validationA field is missing or invalid. For example the password is shorter than 12 characters.
409emailTakenAn account with this email already exists.

Examples

curl
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"}'