Skip to content

Latest commit

 

History

History
8799 lines (5974 loc) · 126 KB

reference.md

File metadata and controls

8799 lines (5974 loc) · 126 KB

Reference

Locations

client.locations.list_practice_locations(...) -> ListPracticeLocationsResponse

📝 Description

Requires locations:read on a practice key or an authorized platform key. Lists active and archived locations by name, with cursor pagination. Use status to filter. Location records are shared between Test and Live for the same practice.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.locations.list_practice_locations(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="loc_01j2y8m6jcc9tt24af5pw9x1bc",
    ending_before="loc_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

limit: typing.Optional[int]

starting_after: typing.Optional[str]

ending_before: typing.Optional[str]

status: typing.Optional[ListPracticeLocationsRequestStatus]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.locations.create_practice_location(...) -> CreatePracticeLocationResponse

📝 Description

Requires locations:write and Idempotency-Key for API keys. Creates an active location with a unique name in this practice. Locations are shared between Test and Live. Use the returned ID for Team location access.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.locations.create_practice_location(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    name="name",
)

⚙️ Parameters

practice_id: str

idempotency_key: str

name: str

city: typing.Optional[str]

country: typing.Optional[str]

line1: typing.Optional[str]

line2: typing.Optional[str]

phone: typing.Optional[str]

postal_code: typing.Optional[str]

state: typing.Optional[str]

timezone: typing.Optional[str] — Optional IANA timezone override. Omit to leave unchanged; null clears it. No timezone is inferred when creating a record.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.locations.get_practice_location(...) -> GetPracticeLocationResponse

📝 Description

Requires locations:read. Returns one active or archived location in the authorized practice.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.locations.get_practice_location(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    location_id="loc_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

location_id: str

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.locations.update_practice_location(...) -> UpdatePracticeLocationResponse

📝 Description

Requires locations:write and Idempotency-Key for API keys. Updates only supplied fields; null clears optional contact and address fields. Archived locations cannot be updated. Changes apply to both Test and Live.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.locations.update_practice_location(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    location_id="loc_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

practice_id: str

location_id: str

idempotency_key: str

city: typing.Optional[str]

country: typing.Optional[str]

line1: typing.Optional[str]

line2: typing.Optional[str]

name: typing.Optional[str]

phone: typing.Optional[str]

postal_code: typing.Optional[str]

state: typing.Optional[str]

timezone: typing.Optional[str] — Optional IANA timezone override. Omit to leave unchanged; null clears it. No timezone is inferred when creating a record.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.locations.archive_practice_location(...) -> ArchivePracticeLocationResponse

📝 Description

Requires locations:write and Idempotency-Key for API keys. Retains the location and historical associations. Archived locations cannot receive new Team assignments. Repeating archive returns the archived location. Changes apply to both Test and Live.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.locations.archive_practice_location(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    location_id="loc_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

practice_id: str

location_id: str

idempotency_key: str

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

API Keys

client.api_keys.create_platform_practice_api_key(...) -> CreatePlatformPracticeApiKeyResponse

📝 Description

Creates a practice API key for a connected practice. Requires a platform key with service_keys:write and every requested scope. The practice key uses the platform key's Test or Live mode and cannot outlive it. Requires Idempotency-Key for safe retries; the secret is returned in the encrypted replay response for 24 hours.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.api_keys.create_platform_practice_api_key(
    practice_id="practiceId",
    idempotency_key="Idempotency-Key",
    name="name",
)

⚙️ Parameters

practice_id: str

idempotency_key: str

name: str

allowed_ips: typing.Optional[typing.List[str]]

expires_at: typing.Optional[str]

scopes: typing.Optional[typing.List[CreatePlatformPracticeApiKeyRequestScopesItem]]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.api_keys.get_api_access() -> GetApiAccessResponse

📝 Description

Returns the subject, mode, and scopes for the API key.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.api_keys.get_api_access()

⚙️ Parameters

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

Account

client.account.get_account(...) -> GetAccountResponse

📝 Description

Returns the platform organization, request livemode, and effective access. API keys report scopes and the service_key role; dashboard sessions report membership permissions. operatingMode describes organization Live access, not the credential's Test/Live mode.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.account.get_account(
    org_id="acct_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

org_id: typing.Optional[str]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

Catalog

client.catalog.list_catalog_items(...) -> ListCatalogItemsResponse

📝 Description

Lists catalog items for the authenticated account and mode. Use view=medications for priced prescription groups with offer counts, pharmacy counts, and strengths; the default view=offers returns individual offers. Use relatedToCatalogItemId to find offers for the same medication and route. When practiceId is supplied, a practice price overrides the platform price and missing overrides inherit the platform price.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.catalog.list_catalog_items(
    related_to_catalog_item_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
    catalog_item_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
    pharmacy_ids="pharm_01j2y8m6jcc9tt24af5pw9x1bc",
    ending_before="cat_01j2y8m6jcc9tt24af5pw9x1bc",
    org_id="acct_01j2y8m6jcc9tt24af5pw9x1bc",
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="cat_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

view: typing.Optional[ListCatalogItemsRequestView]

related_to_catalog_item_id: typing.Optional[str]

catalog_kind: typing.Optional[ListCatalogItemsRequestCatalogKind]

sort: typing.Optional[ListCatalogItemsRequestSort]

catalog_item_id: typing.Optional[str]

availability: typing.Optional[ListCatalogItemsRequestAvailability]

pharmacy_ids: typing.Optional[ListCatalogItemsRequestPharmacyIds]

dosage_forms: typing.Optional[ListCatalogItemsRequestDosageForms]

ending_before: typing.Optional[str]

hide_controlled_substances: typing.Optional[bool]

hide_unpriced: typing.Optional[bool]

limit: typing.Optional[int]

org_id: typing.Optional[str]

practice_id: typing.Optional[str]

query: typing.Optional[str]

requirement: typing.Optional[ListCatalogItemsRequestRequirement]

routes: typing.Optional[ListCatalogItemsRequestRoutes]

starting_after: typing.Optional[str]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.catalog.list_pharmacies(...) -> ListPharmaciesResponse

📝 Description

Lists pharmacies available to the authenticated account, including approved invite-only relationships.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.catalog.list_pharmacies(
    ending_before="pharm_01j2y8m6jcc9tt24af5pw9x1bc",
    org_id="acct_01j2y8m6jcc9tt24af5pw9x1bc",
    pharmacy_id="pharm_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="pharm_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

ending_before: typing.Optional[str]

limit: typing.Optional[int]

org_id: typing.Optional[str]

pharmacy_id: typing.Optional[str]

query: typing.Optional[str]

ships_to_state: typing.Optional[str]

starting_after: typing.Optional[str]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.catalog.list_shipping_options(...) -> ListShippingOptionsResponse

📝 Description

Returns an array of at most 50 reviewed shipping services eligible for a catalog item, destination, and API mode. destinationState must be a USPS state or territory code. Each option has one temperature; pharmacy catalog summaries list all supported temperatures.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.catalog.list_shipping_options(
    catalog_item_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
    destination_state="destinationState",
)

⚙️ Parameters

catalog_item_id: str

destination_state: str

destination_type: typing.Optional[ListShippingOptionsRequestDestinationType]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.catalog.retrieve_prescribing_options(...) -> RetrievePrescribingOptionsResponse

📝 Description

Requires catalog:read. Returns reviewed SIG presets, guided patterns, quantity constraints and product requirements for a practice and mode. Revisions identify changed defaults. No patient-specific rationale or diagnosis is inferred.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.catalog.retrieve_prescribing_options(
    catalog_item_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

catalog_item_id: str

practice_id: str

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

Orders

client.orders.list_orders(...) -> ListOrdersResponse

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.list_orders(
    ending_before="ord_01j2y8m6jcc9tt24af5pw9x1bc",
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
    patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="ord_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

query: typing.Optional[str]

external_order_id: typing.Optional[str]

created_after: typing.Optional[str]

created_before: typing.Optional[str]

ending_before: typing.Optional[str]

limit: typing.Optional[int]

order_id: typing.Optional[str]

patient_id: typing.Optional[str]

patient_external_id: typing.Optional[str]

practice_id: typing.Optional[str]

sort: typing.Optional[ListOrdersRequestSort]

starting_after: typing.Optional[str]

status: typing.Optional[ListOrdersRequestStatus]

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.create_order(...) -> CreateOrderResponse

📝 Description

Creates one unsigned order with 1–20 prescriptions for one patient in one practice. Supply patientId or patient; inline patient creation requires patients:write. Prescriber is optional: select by npi, provider id, or integration-scoped externalId, or leave the draft unassigned until signing. First-use prescriber registration requires team:write. Legacy userId is supported but cannot be combined with prescriber. Idempotency-Key is required.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment
from affinity.orders import CreateOrderRequestPrescriptionsItem, CreateOrderRequestPrescriptionsItemDispensing

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.create_order(
    idempotency_key="Idempotency-Key",
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    prescriptions=[
        CreateOrderRequestPrescriptionsItem(
            days_supply=1,
            dispensing=CreateOrderRequestPrescriptionsItemDispensing(),
            directions="directions",
            medication_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
            quantity="Infinity",
            quantity_unit="quantityUnit",
            refills=1,
        )
    ],
)

⚙️ Parameters

idempotency_key: str

practice_id: str

prescriptions: typing.List[CreateOrderRequestPrescriptionsItem]

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

user_id: typing.Optional[str]

prescriber: typing.Optional[CreateOrderRequestPrescriber]

otc_items: typing.Optional[typing.List[CreateOrderRequestOtcItemsItem]]

external_order_id: typing.Optional[str]

metadata: typing.Optional[typing.Dict[str, typing.Optional[CreateOrderRequestMetadataValue]]]

patient_id: typing.Optional[str]

patient: typing.Optional[CreateOrderRequestPatient]

shipping_address_id: typing.Optional[str]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.get_order(...) -> GetOrderResponse

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.get_order(
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

order_id: str

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.cancel_order(...) -> CancelOrderResponse

📝 Description

Requests cancellation. HTTP 200 means the request was handled; check cancellation.status for confirmed, pending, partial, or failed. Only confirmed means the entire order is cancelled. Shipment possession makes a fulfillment cancellation too late.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.cancel_order(
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    reason="reason",
)

⚙️ Parameters

order_id: str

idempotency_key: str

reason: str

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.act_on_order_exception(...) -> ActOnOrderExceptionResponse

📝 Description

Acknowledge, retry, contact, or resolve an order exception in the credential's Test/Live mode. assign_to_me requires a signed-in dashboard user; API keys receive 400 and may use acknowledge instead. Actor headers do not create a dashboard assignee.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.act_on_order_exception(
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
    exception_id="fex_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    action="acknowledge",
)

⚙️ Parameters

order_id: str

exception_id: str

idempotency_key: str

action: ActOnOrderExceptionRequestAction

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

note: typing.Optional[str]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.list_order_events(...) -> ListOrderEventsResponse

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.list_order_events(
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
    ending_before="evt_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="evt_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

order_id: str

ending_before: typing.Optional[str]

limit: typing.Optional[int]

starting_after: typing.Optional[str]

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.get_order_test_simulation(...) -> GetOrderTestSimulationResponse

📝 Description

Requires orders:write. Available only in Test mode.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.get_order_test_simulation(
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

order_id: str

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.update_order_test_simulation(...) -> UpdateOrderTestSimulationResponse

📝 Description

Requires orders:write and Idempotency-Key. Configure before submission or queue a valid pharmacy event in manual mode. Events use normal order history and Test webhooks. Live requests are rejected.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.update_order_test_simulation(
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    mode="automatic",
    scenario="successful",
)

⚙️ Parameters

order_id: str

idempotency_key: str

mode: UpdateOrderTestSimulationRequestMode

scenario: UpdateOrderTestSimulationRequestScenario

action: typing.Optional[UpdateOrderTestSimulationRequestAction]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.preview_order(...) -> PreviewOrderResponse

📝 Description

Requires orders:write and catalog:read. Supply exactly one of patientId, patientExternalId, or inline patient details. External-ID lookup additionally requires patients:read; inline details require patients:write. Resolves defaults and explicit edits for 1–20 prescriptions. Reuses stored patient details when identifiers match; otherwise previews inline details without creating a patient. Complete previews contain an orders.create input. Does not create records, reserve prices, sign, charge or transmit. No idempotency key is required. Creation and signing recheck current requirements.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment
from affinity.orders import PreviewOrderRequestPrescriptionsItem

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.preview_order(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    prescriptions=[
        PreviewOrderRequestPrescriptionsItem(
            medication_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
        )
    ],
)

⚙️ Parameters

practice_id: str

prescriptions: typing.List[PreviewOrderRequestPrescriptionsItem]

otc_items: typing.Optional[typing.List[PreviewOrderRequestOtcItemsItem]]

patient_id: typing.Optional[str]

patient_external_id: typing.Optional[str]

patient: typing.Optional[PreviewOrderRequestPatient]

user_id: typing.Optional[str]

prescriber: typing.Optional[PreviewOrderRequestPrescriber]

shipping_address_id: typing.Optional[str]

external_order_id: typing.Optional[str]

shipping: typing.Optional[PreviewOrderRequestShipping]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.sign_order(...) -> SignOrderResponse

📝 Description

Requires orders:sign, Idempotency-Key, signatureAttestation, and expectedRevision from the reviewed order. Existing integrations may send expectedVersions instead; supply exactly one. A stale revision returns 409 and requires renewed clinician review. Select prescriber by npi, provider id, or integration-scoped externalId, or inherit the draft's prescriber. First-use registration requires team:write. Actor headers are optional audit metadata with prescriber; legacy userId requires matching clinician actor headers. Signing does not submit to a pharmacy.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.sign_order(
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    signature_attestation=True,
)

⚙️ Parameters

order_id: str

idempotency_key: str

practice_id: str

signature_attestation: bool

user_id: typing.Optional[str]

prescriber: typing.Optional[SignOrderRequestPrescriber]

expected_revision: typing.Optional[str] — Opaque revision of the complete order prescription set. Send the revision you reviewed as expectedRevision; never replace it automatically after a conflict.

expected_versions: typing.Optional[typing.List[SignOrderRequestExpectedVersionsItem]]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.sign_and_submit_order(...) -> SignAndSubmitOrderResponse

📝 Description

Requires orders:sign, Idempotency-Key, signatureAttestation, and expectedRevision from the reviewed order. Existing integrations may send expectedVersions instead; supply exactly one. A stale revision returns 409 and requires renewed clinician review. Select prescriber by npi, provider id, or externalId, or inherit the draft's prescriber. First-use registration requires team:write. Actor headers are optional with prescriber; legacy userId requires matching clinician actor headers. Signs the complete order, then attempts each submission. Signing remains committed if submission fails. Replay the same key after an uncertain response; retry reported submission failures through Submit order with a new key. Submitted means queued, not pharmacy acceptance.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.sign_and_submit_order(
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    signature_attestation=True,
)

⚙️ Parameters

order_id: str

idempotency_key: str

practice_id: str

signature_attestation: bool

user_id: typing.Optional[str]

prescriber: typing.Optional[SignAndSubmitOrderRequestPrescriber]

expected_revision: typing.Optional[str] — Opaque revision of the complete order prescription set. Send the revision you reviewed as expectedRevision; never replace it automatically after a conflict.

expected_versions: typing.Optional[typing.List[SignAndSubmitOrderRequestExpectedVersionsItem]]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.submit_order(...) -> SubmitOrderResponse

📝 Description

Requires orders:sign and Idempotency-Key. Queues signed prescriptions after rechecking authorization, signature integrity, billing, and fulfillment eligibility. Track pharmacy acceptance through order reads and webhooks. After a partial failure, retry submission with a new idempotency key; already queued prescriptions are not duplicated.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.submit_order(
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

order_id: str

idempotency_key: str

practice_id: str

user_id: typing.Optional[str]

prescriber: typing.Optional[SubmitOrderRequestPrescriber]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.reject_order(...) -> RejectOrderResponse

📝 Description

Requires orders:sign and Idempotency-Key. Select a prescriber or inherit the draft's prescriber. Legacy userId requires matching clinician actor headers. Supply expectedRevision from the reviewed order, or expectedVersions for existing integrations. Permanently rejects the complete unsigned order after checking its revision.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.reject_order(
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    reason="reason",
)

⚙️ Parameters

order_id: str

idempotency_key: str

practice_id: str

reason: str

user_id: typing.Optional[str]

prescriber: typing.Optional[RejectOrderRequestPrescriber]

expected_revision: typing.Optional[str] — Opaque revision of the complete order prescription set. Send the revision you reviewed as expectedRevision; never replace it automatically after a conflict.

expected_versions: typing.Optional[typing.List[RejectOrderRequestExpectedVersionsItem]]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.add_order_prescription(...) -> AddOrderPrescriptionResponse

📝 Description

Requires orders:write, Idempotency-Key and expectedRevision from the order being edited. Existing integrations may send expectedVersions instead; supply exactly one. Adds a complete prescription to an unsigned Order and returns all new versions. Omitted actor context defaults to the authenticated service account as a system actor. Patient and prescriber attribution stay fixed. Signed orders cannot be amended through this endpoint. Signing and submission require orders:sign through their separate endpoints.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment
from affinity.orders import AddOrderPrescriptionRequestPrescription, AddOrderPrescriptionRequestPrescriptionDispensing

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.add_order_prescription(
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    prescription=AddOrderPrescriptionRequestPrescription(
        days_supply=1,
        dispensing=AddOrderPrescriptionRequestPrescriptionDispensing(),
        directions="directions",
        medication_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
        quantity="Infinity",
        quantity_unit="quantityUnit",
        refills=1,
    ),
)

⚙️ Parameters

order_id: str

idempotency_key: str

practice_id: str

prescription: AddOrderPrescriptionRequestPrescription

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

metadata: typing.Optional[typing.Dict[str, typing.Optional[AddOrderPrescriptionRequestMetadataValue]]]

expected_revision: typing.Optional[str] — Opaque revision of the complete order prescription set. Send the revision you reviewed as expectedRevision; never replace it automatically after a conflict.

expected_versions: typing.Optional[typing.List[AddOrderPrescriptionRequestExpectedVersionsItem]]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.update_order_prescription(...) -> UpdateOrderPrescriptionResponse

📝 Description

Requires orders:write, Idempotency-Key and expectedRevision from the order being edited. Existing integrations may send expectedVersions instead; supply exactly one. Replaces one prescription with complete medication instructions and returns all new versions. Omitted actor context defaults to the authenticated service account as a system actor. Patient and prescriber attribution stay fixed. Signed orders cannot be amended through this endpoint. Signing and submission require orders:sign through their separate endpoints.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment
from affinity.orders import UpdateOrderPrescriptionRequestPrescription, UpdateOrderPrescriptionRequestPrescriptionDispensing

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.update_order_prescription(
    order_id="ord_01j2y8m6jcc9tt24af5pw9x1bc",
    prescription_id="rx_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    prescription=UpdateOrderPrescriptionRequestPrescription(
        days_supply=1,
        dispensing=UpdateOrderPrescriptionRequestPrescriptionDispensing(),
        directions="directions",
        medication_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
        quantity="Infinity",
        quantity_unit="quantityUnit",
        refills=1,
    ),
)

⚙️ Parameters

order_id: str

prescription_id: str

idempotency_key: str

practice_id: str

prescription: UpdateOrderPrescriptionRequestPrescription

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

metadata: typing.Optional[typing.Dict[str, typing.Optional[UpdateOrderPrescriptionRequestMetadataValue]]]

expected_revision: typing.Optional[str] — Opaque revision of the complete order prescription set. Send the revision you reviewed as expectedRevision; never replace it automatically after a conflict.

expected_versions: typing.Optional[typing.List[UpdateOrderPrescriptionRequestExpectedVersionsItem]]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.orders.create_order_batch(...) -> CreateOrderBatchResponse

📝 Description

Creates 1–20 orders for distinct patients in one practice, each with 1–20 prescriptions. Each accepts patientId or inline patient details. Orders and newly created patients commit atomically; any failure saves none. Requires orders:write and Idempotency-Key; inline patients also require patients:write. Omitted actor context defaults to the authenticated service account as a system actor. Sign and submit each resulting order separately using orders:sign.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment
from affinity.orders import CreateOrderBatchRequestOrdersItem, CreateOrderBatchRequestOrdersItemPrescriptionsItem, CreateOrderBatchRequestOrdersItemPrescriptionsItemDispensing

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.orders.create_order_batch(
    idempotency_key="Idempotency-Key",
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    orders=[
        CreateOrderBatchRequestOrdersItem(
            prescriptions=[
                CreateOrderBatchRequestOrdersItemPrescriptionsItem(
                    days_supply=1,
                    dispensing=CreateOrderBatchRequestOrdersItemPrescriptionsItemDispensing(),
                    directions="directions",
                    medication_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
                    quantity="Infinity",
                    quantity_unit="quantityUnit",
                    refills=1,
                )
            ],
        )
    ],
)

⚙️ Parameters

idempotency_key: str

practice_id: str

orders: typing.List[CreateOrderBatchRequestOrdersItem]

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

user_id: typing.Optional[str]

prescriber: typing.Optional[CreateOrderBatchRequestPrescriber]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

Webhooks

client.webhooks.list_webhook_endpoints(...) -> ListWebhookEndpointsResponse

📝 Description

Requires webhooks:read. Returns endpoints owned by the key organization, or the organization selected with X-Affinity-Organization-Id. Platform delegation requires a webhook grant in the key's mode.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.webhooks.list_webhook_endpoints(
    ending_before="whe_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="whe_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

ending_before: typing.Optional[str]

limit: typing.Optional[int]

starting_after: typing.Optional[str]

affinity_organization_id: typing.Optional[str] — Defaults to the API key organization. A platform may select a practice or pharmacy only with an explicit webhook grant in this mode. This changes the webhook owner, not the caller or event subscriptions.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.webhooks.create_webhook_endpoint(...) -> CreateWebhookEndpointResponse

📝 Description

Requires webhooks:write and Idempotency-Key. Defaults to the API key organization. A platform can select a practice or pharmacy owner with X-Affinity-Organization-Id and an explicit webhook grant. For platform-owned endpoints, practiceIds narrows delivery to selected connected practices. An empty filter receives all otherwise-authorized events.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.webhooks.create_webhook_endpoint(
    idempotency_key="Idempotency-Key",
    url="url",
)

⚙️ Parameters

idempotency_key: str

url: str

affinity_organization_id: typing.Optional[str] — Defaults to the API key organization. A platform may select a practice or pharmacy only with an explicit webhook grant in this mode. This changes the webhook owner, not the caller or event subscriptions.

practice_ids: typing.Optional[typing.List[str]]

description: typing.Optional[str]

payload_style: typing.Optional[CreateWebhookEndpointRequestPayloadStyle]

subscribed_events: typing.Optional[typing.List[CreateWebhookEndpointRequestSubscribedEventsItem]]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.webhooks.delete_webhook_endpoint(...) -> DeleteWebhookEndpointResponse

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.webhooks.delete_webhook_endpoint(
    endpoint_id="whe_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

endpoint_id: str

idempotency_key: str

affinity_organization_id: typing.Optional[str] — Defaults to the API key organization. A platform may select a practice or pharmacy only with an explicit webhook grant in this mode. This changes the webhook owner, not the caller or event subscriptions.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.webhooks.update_webhook_endpoint(...) -> UpdateWebhookEndpointResponse

📝 Description

Requires webhooks:write and Idempotency-Key. Updates an endpoint in the selected organization and mode. Omitted practiceIds preserves the filter; an empty array removes the practice filter. Subscription changes apply to newly generated events.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.webhooks.update_webhook_endpoint(
    endpoint_id="whe_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

endpoint_id: str

idempotency_key: str

affinity_organization_id: typing.Optional[str] — Defaults to the API key organization. A platform may select a practice or pharmacy only with an explicit webhook grant in this mode. This changes the webhook owner, not the caller or event subscriptions.

practice_ids: typing.Optional[typing.List[str]]

description: typing.Optional[str]

payload_style: typing.Optional[UpdateWebhookEndpointRequestPayloadStyle]

status: typing.Optional[UpdateWebhookEndpointRequestStatus]

subscribed_events: typing.Optional[typing.List[UpdateWebhookEndpointRequestSubscribedEventsItem]]

url: typing.Optional[str]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.webhooks.rotate_webhook_endpoint_secret(...) -> RotateWebhookEndpointSecretResponse

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.webhooks.rotate_webhook_endpoint_secret(
    endpoint_id="whe_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

endpoint_id: str

idempotency_key: str

affinity_organization_id: typing.Optional[str] — Defaults to the API key organization. A platform may select a practice or pharmacy only with an explicit webhook grant in this mode. This changes the webhook owner, not the caller or event subscriptions.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.webhooks.test_webhook_endpoint(...) -> TestWebhookEndpointResponse

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.webhooks.test_webhook_endpoint(
    endpoint_id="whe_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

endpoint_id: str

idempotency_key: str

affinity_organization_id: typing.Optional[str] — Defaults to the API key organization. A platform may select a practice or pharmacy only with an explicit webhook grant in this mode. This changes the webhook owner, not the caller or event subscriptions.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.webhooks.list_webhook_events(...) -> ListWebhookEventsResponse

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.webhooks.list_webhook_events(
    ending_before="evt_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="evt_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

ending_before: typing.Optional[str]

limit: typing.Optional[int]

status: typing.Optional[ListWebhookEventsRequestStatus]

starting_after: typing.Optional[str]

affinity_organization_id: typing.Optional[str] — Defaults to the API key organization. A platform may select a practice or pharmacy only with an explicit webhook grant in this mode. This changes the webhook owner, not the caller or event subscriptions.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.webhooks.get_webhook_event(...) -> GetWebhookEventResponse

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.webhooks.get_webhook_event(
    event_id="evt_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

event_id: str

affinity_organization_id: typing.Optional[str] — Defaults to the API key organization. A platform may select a practice or pharmacy only with an explicit webhook grant in this mode. This changes the webhook owner, not the caller or event subscriptions.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.webhooks.replay_webhook_event(...) -> ReplayWebhookEventResponse

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.webhooks.replay_webhook_event(
    event_id="evt_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

event_id: str

idempotency_key: str

affinity_organization_id: typing.Optional[str] — Defaults to the API key organization. A platform may select a practice or pharmacy only with an explicit webhook grant in this mode. This changes the webhook owner, not the caller or event subscriptions.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.webhooks.list_webhook_grants(...) -> ListWebhookGrantsResponse

📝 Description

Requires webhooks:read on the owning practice or pharmacy key. Lists platform webhook grants in the key's mode. Platforms cannot list or grant themselves delegated access.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.webhooks.list_webhook_grants(
    starting_after="acct_01j2y8m6jcc9tt24af5pw9x1bc",
    ending_before="acct_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

limit: typing.Optional[int]

starting_after: typing.Optional[str]

ending_before: typing.Optional[str]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.webhooks.save_webhook_grant(...) -> SaveWebhookGrantResponse

📝 Description

Requires webhooks:write on the owning practice or pharmacy key and Idempotency-Key. Grants or replaces a platform's webhook permissions in this mode. A practice must already be connected to that platform. The grant does not give the platform access to other API resources.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.webhooks.save_webhook_grant(
    platform_id="acct_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    scopes=[
        "webhooks:read"
    ],
)

⚙️ Parameters

platform_id: str

idempotency_key: str

scopes: typing.List[SaveWebhookGrantRequestScopesItem]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.webhooks.revoke_webhook_grant(...) -> RevokeWebhookGrantResponse

📝 Description

Requires webhooks:write on the owning practice or pharmacy key and Idempotency-Key. Removes platform webhook access in this mode. Existing endpoints remain owned by the practice or pharmacy and continue operating.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.webhooks.revoke_webhook_grant(
    platform_id="acct_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

platform_id: str

idempotency_key: str

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

Team

client.team.register_user(...) -> RegisterUserResponse

📝 Description

Requires team:write and Idempotency-Key. Registers a practice member without an invitation. Test requires synthetic .test emails and Affinity Test NPIs. Live requires approved integration and practice access. Identity attestation records the integration's assertion; it does not verify login email or clinical credentials. Existing memberships and verified provider records are preserved. Use the returned user ID for orders and signing.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.register_user(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    external_id="externalId",
    email="email",
    name="name",
    role="administrator",
    identity_attestation=True,
)

⚙️ Parameters

practice_id: str

idempotency_key: str

external_id: str

email: str

name: str

role: RegisterUserRequestRole

identity_attestation: bool

roles: typing.Optional[typing.List[RegisterUserRequestRolesItem]]

profile_details: typing.Optional[RegisterUserRequestProfileDetails]

npi: typing.Optional[str]

licenses: typing.Optional[typing.List[RegisterUserRequestLicensesItem]]

legal_name: typing.Optional[str]

display_name: typing.Optional[str]

credentials: typing.Optional[str]

address: typing.Optional[RegisterUserRequestAddress]

phone: typing.Optional[str]

location_ids: typing.Optional[typing.List[str]]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.list_practice_team_invitations(...) -> ListPracticeTeamInvitationsResponse

📝 Description

Requires team:read. Lists practice invitations, including invitations sent in Clinic. Filter by pending, expired, accepted, declined, or revoked status, exact email, or your integration externalId. Only your integration and API key mode can see its external identity and onboarding state. Follow person.nextActions after invitation acceptance.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.list_practice_team_invitations(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="invite_01j2y8m6jcc9tt24af5pw9x1bc",
    ending_before="invite_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

limit: typing.Optional[int]

starting_after: typing.Optional[str]

ending_before: typing.Optional[str]

status: typing.Optional[ListPracticeTeamInvitationsRequestStatus]

email: typing.Optional[str]

external_id: typing.Optional[str] — Match this integration's external identity in the API key's mode.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.invite_practice_team_person(...) -> InvitePracticeTeamPersonResponse

📝 Description

Requires team:write on the practice key or its platform key. Use roles to combine administrator, prescriber, clinical_staff, billing, or developer presets. Ownership uses the protected owner designation. The singular role field remains available for single-role assignments. Creates a real organization invitation and optional prescriber setup. The recipient must accept with their Affinity account. Repeating the same external identity retries pending invitation delivery. Accepted invitations do not change existing access. Team membership is shared between Test and Live; the external identity is mode-scoped. Keys cannot accept invitations. Headless registration and signing use separate endpoints.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.invite_practice_team_person(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    external_id="externalId",
    email="email",
    name="name",
)

⚙️ Parameters

practice_id: str

idempotency_key: str

external_id: str

email: str

name: str

role: typing.Optional[InvitePracticeTeamPersonRequestRole]

roles: typing.Optional[typing.List[InvitePracticeTeamPersonRequestRolesItem]]

profile_details: typing.Optional[InvitePracticeTeamPersonRequestProfileDetails]

npi: typing.Optional[str]

licenses: typing.Optional[typing.List[InvitePracticeTeamPersonRequestLicensesItem]]

legal_name: typing.Optional[str]

display_name: typing.Optional[str]

credentials: typing.Optional[str]

address: typing.Optional[InvitePracticeTeamPersonRequestAddress]

phone: typing.Optional[str]

location_ids: typing.Optional[typing.List[str]]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.get_practice_team(...) -> GetPracticeTeamResponse

📝 Description

Requires team:read. Returns counts of members, invitations, and prescribers. Use the paginated members, prescribers, and invitations collections for individual records. Team access and clinician credentials are shared between Test and Live.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.get_practice_team(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.list_practice_team_members(...) -> ListPracticeTeamMembersResponse

📝 Description

Requires team:read. Search the roster by name or email, and filter by role or membership status. Includes members invited in Clinic, location access, and account-specific prescriber connections. Memberships are shared between Test and Live.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.list_practice_team_members(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="mbr_01j2y8m6jcc9tt24af5pw9x1bc",
    ending_before="mbr_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

limit: typing.Optional[int]

starting_after: typing.Optional[str]

ending_before: typing.Optional[str]

search: typing.Optional[str]

role: typing.Optional[ListPracticeTeamMembersRequestRole]

status: typing.Optional[ListPracticeTeamMembersRequestStatus]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.list_practice_team_prescribers(...) -> ListPracticeTeamPrescribersResponse

📝 Description

Requires team:read. Filter practice prescribers by name, NPI, state, and practice status. Records include submitted licenses and their IDs. Signing authority also requires an active account connection, Live practice access, and prescription eligibility.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.list_practice_team_prescribers(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="prov_01j2y8m6jcc9tt24af5pw9x1bc",
    ending_before="prov_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

limit: typing.Optional[int]

starting_after: typing.Optional[str]

ending_before: typing.Optional[str]

search: typing.Optional[str]

npi: typing.Optional[str]

state: typing.Optional[str] — Match a submitted license jurisdiction. This does not establish signing eligibility.

status: typing.Optional[ListPracticeTeamPrescribersRequestStatus]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.get_practice_team_member(...) -> GetPracticeTeamMemberResponse

📝 Description

Requires team:read. Returns current account membership, roles, location access, and prescriber connection. The member ID identifies practice access; it is not the integration user ID used by orders.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.get_practice_team_member(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    member_id="mbr_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

member_id: str

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.update_practice_team_member(...) -> UpdatePracticeTeamMemberResponse

📝 Description

Requires team:write. Supply role, status, or locationIds; omitted values stay unchanged. A role replaces existing roles. Disable access with status disabled. An empty locationIds array grants all practice locations. Ownership changes require an active practice owner using a personal API key; service keys manage non-owner memberships. The final active owner cannot be removed. Changes apply to both Test and Live. Sign-in email and account security remain account settings.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.update_practice_team_member(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    member_id="mbr_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

practice_id: str

member_id: str

idempotency_key: str

role: typing.Optional[UpdatePracticeTeamMemberRequestRole]

roles: typing.Optional[typing.List[UpdatePracticeTeamMemberRequestRolesItem]]

status: typing.Optional[UpdatePracticeTeamMemberRequestStatus]

location_ids: typing.Optional[typing.List[str]] — Replace location access. An empty array grants access to all practice locations.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.get_practice_team_prescriber(...) -> GetPracticeTeamPrescriberResponse

📝 Description

Requires team:read. Returns the clinical profile and submitted licenses, including license IDs. This is setup information, not a signing authorization.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.get_practice_team_prescriber(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    prescriber_id="prov_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

prescriber_id: str

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.update_practice_team_prescriber(...) -> UpdatePracticeTeamPrescriberResponse

📝 Description

Requires team:write. Set practiceStatus to inactive to remove prescribing access in this practice, or active to restore an existing association. This does not create membership or signing authority. Practice status applies to Test and Live. Shared identity and license edits require Affinity support.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.update_practice_team_prescriber(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    prescriber_id="prov_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

practice_id: str

prescriber_id: str

idempotency_key: str

display_name: typing.Optional[str]

legal_name: typing.Optional[str]

credentials: typing.Optional[str]

phone: typing.Optional[str]

address: typing.Optional[UpdatePracticeTeamPrescriberRequestAddress]

practice_status: typing.Optional[UpdatePracticeTeamPrescriberRequestPracticeStatus]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.create_practice_team_license(...) -> CreatePracticeTeamLicenseResponse

📝 Description

Requires team:write and an active accepted prescriber account connection in this practice. Adds a license. Expiration is optional, but must be in the future when supplied. An exact repeat returns the existing license; update an existing license with PATCH and its license ID. Licenses are shared across practices and Test/Live. Other licenses stay unchanged.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.create_practice_team_license(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    prescriber_id="prov_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    state="state",
    license_number="licenseNumber",
)

⚙️ Parameters

practice_id: str

prescriber_id: str

idempotency_key: str

state: str

license_number: str

expires_at: typing.Optional[str]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.update_practice_team_license(...) -> UpdatePracticeTeamLicenseResponse

📝 Description

Requires team:write and an active accepted prescriber account connection in this practice. Correct the state or license number, or set or clear the optional expiresAt value. A supplied expiration must be in the future. Other licenses stay unchanged. Changes apply across practices and Test/Live.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.update_practice_team_license(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    prescriber_id="prov_01j2y8m6jcc9tt24af5pw9x1bc",
    license_id="lic_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

practice_id: str

prescriber_id: str

license_id: str

idempotency_key: str

state: typing.Optional[str]

license_number: typing.Optional[str]

expires_at: typing.Optional[str]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.get_practice_team_invitation(...) -> GetPracticeTeamInvitationResponse

📝 Description

Requires team:read. Returns invitation status and current onboarding state for your integration. An accepted invitation can still have disabled membership or pending clinical review. Invitation tokens are never returned.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.get_practice_team_invitation(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    invitation_id="invite_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

invitation_id: str

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.revoke_practice_team_invitation(...) -> RevokePracticeTeamInvitationResponse

📝 Description

Requires team:write. Revokes a pending or expired invitation and its pending prescriber account connection. Repeating the revoke returns the revoked invitation. Accepted invitations return 409; disable the member instead. Retains invitation history.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.revoke_practice_team_invitation(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    invitation_id="invite_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

practice_id: str

invitation_id: str

idempotency_key: str

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.team.resend_practice_team_invitation(...) -> ResendPracticeTeamInvitationResponse

📝 Description

Requires team:write. Resends a pending or expired invitation with the same ID, recipient, roles, and locations. The previous link stops working and the new link expires in seven days. Accepted and revoked invitations return 409. A 502 means the invitation was saved but email delivery could not be confirmed; retry this operation.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.team.resend_practice_team_invitation(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    invitation_id="invite_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

practice_id: str

invitation_id: str

idempotency_key: str

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

Patients

client.patients.list_patient_addresses(...) -> ListPatientAddressesResponse

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.patients.list_patient_addresses(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="addr_01j2y8m6jcc9tt24af5pw9x1bc",
    ending_before="addr_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

patient_id: str

status: typing.Optional[ListPatientAddressesRequestStatus]

starting_after: typing.Optional[str]

ending_before: typing.Optional[str]

limit: typing.Optional[int]

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.patients.create_patient_address(...) -> CreatePatientAddressResponse

📝 Description

Returns the existing active address for a normalized duplicate. The first address becomes the default. API keys require Idempotency-Key.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment
from affinity.patients import CreatePatientAddressRequestAddress

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.patients.create_patient_address(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    address=CreatePatientAddressRequestAddress(
        city="city",
        line1="line1",
        postal_code="postalCode",
        state="state",
    ),
)

⚙️ Parameters

practice_id: str

patient_id: str

idempotency_key: str

address: CreatePatientAddressRequestAddress

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

label: typing.Optional[str]

preferred_shipping: typing.Optional[bool]

recipient_name: typing.Optional[str]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.patients.archive_patient_address(...) -> ArchivePatientAddressResponse

📝 Description

Preserves the address ID and history. Archiving the default selects the oldest remaining active address. Existing orders remain unchanged.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.patients.archive_patient_address(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
    address_id="addr_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

practice_id: str

patient_id: str

address_id: str

idempotency_key: str

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.patients.update_patient_address(...) -> UpdatePatientAddressResponse

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.patients.update_patient_address(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
    address_id="addr_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

practice_id: str

patient_id: str

address_id: str

idempotency_key: str

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

address: typing.Optional[UpdatePatientAddressRequestAddress]

label: typing.Optional[str]

recipient_name: typing.Optional[str]

preferred_shipping: typing.Optional[bool]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.patients.set_default_patient_address(...) -> SetDefaultPatientAddressResponse

📝 Description

Changes delivery selection for future drafts, without changing patient clinical location or existing signed orders.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.patients.set_default_patient_address(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
    address_id="addr_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

practice_id: str

patient_id: str

address_id: str

idempotency_key: str

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.patients.list_patients(...) -> ListPatientsResponse

📝 Description

Lists patients in one practice and mode. Use externalId for an exact match in the calling integration's namespace. Use externalIdentitySource with externalIdentityValue to search an explicit alias. Identity matching is case-sensitive after trimming whitespace. Other filters also apply.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.patients.list_patients(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    ending_before="pat_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="pat_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

ending_before: typing.Optional[str]

external_id: typing.Optional[str]

external_identity_source: typing.Optional[str]

external_identity_value: typing.Optional[str]

gender: typing.Optional[ListPatientsRequestGender]

last_order_after: typing.Optional[str]

last_order_before: typing.Optional[str]

limit: typing.Optional[int]

program: typing.Optional[str]

query: typing.Optional[str]

sort: typing.Optional[ListPatientsRequestSort]

starting_after: typing.Optional[str]

states: typing.Optional[str]

status: typing.Optional[ListPatientsRequestStatus]

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.patients.create_patient(...) -> CreatePatientResponse

📝 Description

Creates a patient or resolves a matching externalId or external identity within this practice and mode. externalId belongs to the calling integration; externalIdentities holds aliases from other systems. Resolution preserves existing demographics; use PATCH to update them. Conflicting identifiers return 409. Email never merges patients. API keys require Idempotency-Key.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment
from affinity.patients import CreatePatientRequestName

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.patients.create_patient(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    date_of_birth="dateOfBirth",
    name=CreatePatientRequestName(
        first="first",
        last="last",
    ),
)

⚙️ Parameters

practice_id: str

idempotency_key: str

date_of_birth: str

name: CreatePatientRequestName

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

address: typing.Optional[CreatePatientRequestAddress]

clinical_profile: typing.Optional[CreatePatientRequestClinicalProfile]

email: typing.Optional[str]

external_id: typing.Optional[str]

external_identities: typing.Optional[typing.List[CreatePatientRequestExternalIdentitiesItem]]

addresses: typing.Optional[typing.List[CreatePatientRequestAddressesItem]]

encounters: typing.Optional[typing.List[CreatePatientRequestEncountersItem]]

gender: typing.Optional[CreatePatientRequestGender]

location_id: typing.Optional[str]

metadata: typing.Optional[typing.Dict[str, typing.Any]]

medical_record_number: typing.Optional[str]

measurements: typing.Optional[typing.List[CreatePatientRequestMeasurementsItem]]

phone: typing.Optional[str]

programs: typing.Optional[typing.List[CreatePatientRequestProgramsItem]]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.patients.get_patient(...) -> GetPatientResponse

📝 Description

Returns one patient in the authorized practice and mode.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.patients.get_patient(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

patient_id: str

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.patients.delete_patient(...) -> DeletePatientResponse

📝 Description

Requires patients:write and Idempotency-Key for API keys. Permanently deletes a patient with no order history. Any order history returns 409; use Update patient with status archived instead. Available to practice keys and authorized platform keys. Reusing the same idempotency key returns the original deletion result.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.patients.delete_patient(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

practice_id: str

patient_id: str

idempotency_key: str

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.patients.update_patient(...) -> UpdatePatientResponse

📝 Description

Updates a patient in the current practice and mode. Omitted fields remain unchanged; null clears an optional field. externalId updates the calling integration's identifier. externalIdentities replaces its explicit aliases. Identifiers cannot be reassigned from another patient. API keys require Idempotency-Key.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.patients.update_patient(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
)

⚙️ Parameters

practice_id: str

patient_id: str

idempotency_key: str

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

address: typing.Optional[UpdatePatientRequestAddress]

clinical_profile: typing.Optional[UpdatePatientRequestClinicalProfile]

date_of_birth: typing.Optional[str]

email: typing.Optional[str]

external_id: typing.Optional[str]

external_identities: typing.Optional[typing.List[UpdatePatientRequestExternalIdentitiesItem]]

addresses: typing.Optional[typing.List[UpdatePatientRequestAddressesItem]]

encounters: typing.Optional[typing.List[UpdatePatientRequestEncountersItem]]

gender: typing.Optional[UpdatePatientRequestGender]

location_id: typing.Optional[str]

metadata: typing.Optional[typing.Dict[str, typing.Any]]

medical_record_number: typing.Optional[str]

measurements: typing.Optional[typing.List[UpdatePatientRequestMeasurementsItem]]

name: typing.Optional[UpdatePatientRequestName]

programs: typing.Optional[typing.List[UpdatePatientRequestProgramsItem]]

phone: typing.Optional[str]

status: typing.Optional[UpdatePatientRequestStatus]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.patients.get_patient_allergies(...) -> GetPatientAllergiesResponse

📝 Description

Returns the patient's structured allergy entries and review status. A not_reviewed status is not a no-known-allergies assertion and blocks clinical review and signing.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.patients.get_patient_allergies(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

patient_id: str

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.patients.replace_patient_allergies(...) -> ReplacePatientAllergiesResponse

📝 Description

Replaces the patient's structured allergy record. Sending no_known is the explicit no-known-allergies acknowledgement; recorded requires at least one entry. Idempotency-Key is required.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment
from affinity.patients import ReplacePatientAllergiesRequestAllergiesItem, ReplacePatientAllergiesRequestAllergiesItemReactionsItem

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.patients.replace_patient_allergies(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    patient_id="pat_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    allergies=[
        ReplacePatientAllergiesRequestAllergiesItem(
            category="drug",
            reactions=[
                ReplacePatientAllergiesRequestAllergiesItemReactionsItem(
                    display="display",
                )
            ],
            source="Doctor",
            substance="substance",
            verification_status="unconfirmed",
        )
    ],
    review_status="not_reviewed",
)

⚙️ Parameters

practice_id: str

patient_id: str

idempotency_key: str

allergies: typing.List[ReplacePatientAllergiesRequestAllergiesItem]

review_status: ReplacePatientAllergiesRequestReviewStatus

affinity_actor_id: typing.Optional[str] — Required for user actors and optional for system actors. Omit both actor headers to use the authenticated service account as a system actor.

affinity_actor_type: typing.Optional[str] — Use user when a person initiated the action and system for autonomous work. Omit both actor headers to default to system.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

Practices

client.practices.list_practices(...) -> ListPracticesResponse

📝 Description

Returns the practices that belong to the platform. The default Affinity-Version is 2026-09-28.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.practices.list_practices(
    ending_before="prac_01j2y8m6jcc9tt24af5pw9x1bc",
    starting_after="prac_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

search: typing.Optional[str] — Case-insensitive search by practice name or external ID.

ending_before: typing.Optional[str]

limit: typing.Optional[int]

starting_after: typing.Optional[str]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.practices.create_practice(...) -> CreatePracticeResponse

📝 Description

Creates a practice owned by the platform. Set liveEnabled to true to enable Live access at creation with an approved platform and a Live request. Defaults to false. Requires practices:write. Send Idempotency-Key when you retry the same request.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment
from affinity.practices import CreatePracticeRequestAddress, CreatePracticeRequestAttestations, CreatePracticeRequestPrescribersItem, CreatePracticeRequestPrimaryContact

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.practices.create_practice(
    address=CreatePracticeRequestAddress(
        city="Los Angeles",
        country="US",
        line1="100 Practice Way",
        postal_code="90001",
        state="CA",
    ),
    attestations=CreatePracticeRequestAttestations(
        authorized_practice_relationship=True,
        authorized_phi_transfer=True,
        minimum_necessary_phi=True,
        provider_data_accuracy=True,
    ),
    external_id="practice_123",
    legal_name="Example Medical Group PLLC",
    metadata={
        "key": "value"
    },
    name="Example Medical Group",
    prescribers=[
        CreatePracticeRequestPrescribersItem(
            credentials="MD",
            license_states=[
                "CA"
            ],
            name="Alex Morgan",
            npi="1234567893",
        )
    ],
    primary_contact=CreatePracticeRequestPrimaryContact(
        email="operations@example-practice.com",
        name="Jordan Lee",
    ),
    support_email="support@example-practice.com",
)

⚙️ Parameters

address: CreatePracticeRequestAddress

attestations: CreatePracticeRequestAttestations

name: str

idempotency_key: typing.Optional[str]

live_enabled: typing.Optional[bool] — Enable Live access at creation. Requires an approved platform and a Live request. Defaults to false.

compliance_contact: typing.Optional[CreatePracticeRequestComplianceContact]

external_id: typing.Optional[str]

legal_name: typing.Optional[str]

metadata: typing.Optional[typing.Dict[str, typing.Any]]

prescribers: typing.Optional[typing.List[CreatePracticeRequestPrescribersItem]]

primary_contact: typing.Optional[CreatePracticeRequestPrimaryContact]

support_email: typing.Optional[str]

support_phone: typing.Optional[str]

timezone: typing.Optional[str] — Optional IANA timezone override. Omit to leave unchanged; null clears it. No timezone is inferred when creating a record.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.practices.get_practice(...) -> GetPracticeResponse

📝 Description

Returns one practice that belongs to the platform.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.practices.get_practice(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.practices.update_practice(...) -> UpdatePracticeResponse

📝 Description

Updates one practice owned by the platform. Set liveEnabled to true or false to control Live access with an approved platform and a Live request. Affinity Admin decisions take precedence. Requires practices:write. Send Idempotency-Key when you retry the same request.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.practices.update_practice(
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

practice_id: str

idempotency_key: typing.Optional[str]

live_enabled: typing.Optional[bool] — Enable or disable Live access for an owned practice. Requires an approved platform and a Live request. Affinity Admin decisions take precedence.

address: typing.Optional[UpdatePracticeRequestAddress]

attestations: typing.Optional[UpdatePracticeRequestAttestations]

compliance_contact: typing.Optional[UpdatePracticeRequestComplianceContact]

external_id: typing.Optional[str]

legal_name: typing.Optional[str]

metadata: typing.Optional[typing.Dict[str, typing.Any]]

name: typing.Optional[str]

prescribers: typing.Optional[typing.List[UpdatePracticeRequestPrescribersItem]]

primary_contact: typing.Optional[UpdatePracticeRequestPrimaryContact]

support_email: typing.Optional[str]

support_phone: typing.Optional[str]

timezone: typing.Optional[str] — Optional IANA timezone override. Omit to leave unchanged; null clears it. No timezone is inferred when creating a record.

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

Platform Pricing

client.platform_pricing.platform_public_api_selling_prices_read_selling_price(...) -> PlatformPublicApiSellingPricesReadSellingPriceResponse

📝 Description

Requires selling_prices:read. Omit practiceId for the platform default, or supply a managed practice. A null amount inherits the next applicable price. Amounts use the catalog pricing basis, in USD cents. purchaseAmountCents is the platform's Affinity purchase price for that same basis. requiresReview indicates changed product pricing terms, not a below-purchase-price discount.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.platform_pricing.platform_public_api_selling_prices_read_selling_price(
    catalog_item_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
    practice_id="prac_01j2y8m6jcc9tt24af5pw9x1bc",
)

⚙️ Parameters

catalog_item_id: str

practice_id: typing.Optional[str]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.

client.platform_pricing.platform_public_api_selling_prices_update_selling_price(...) -> PlatformPublicApiSellingPricesUpdateSellingPriceResponse

📝 Description

Requires selling_prices:write. Sets a platform default or managed practice override in the current Test/Live mode. Send baseVersion from Read selling price. Null removes the override. Prices use the catalog pricing basis. Intentional discounts below purchaseAmountCents are allowed; compare these amounts to warn about selling below your Affinity purchase price. This does not change the platform's Affinity purchase price or collect practice payments.

🔌 Usage

from affinity import Affinity
from affinity.environment import AffinityEnvironment

client = Affinity(
    api_key="<value>",
    environment=AffinityEnvironment.PRODUCTION,
)

client.platform_pricing.platform_public_api_selling_prices_update_selling_price(
    catalog_item_id="cat_01j2y8m6jcc9tt24af5pw9x1bc",
    idempotency_key="Idempotency-Key",
    base_version=1,
)

⚙️ Parameters

catalog_item_id: str

idempotency_key: str

base_version: int

practice_id: typing.Optional[str]

amount_cents: typing.Optional[int]

request_options: typing.Optional[RequestOptions] — Request-specific configuration.