Flexpa
Developer PortalFeedbackContact usOnboard

Guides

  • Home
  • Quickstart
  • Financial Data

Network

  • Network guide
  • Directory
  • Updates

Consent

  • Link SDK
  • Patient access

Records

  • FHIR API
  • Node SDK
    • Prerequisites
    • Installation
    • Getting Started
    • Initialize
    • Link API
    • FHIR API
    • Utilities
  • FHIR Introduction
  • Usage
  • Terminology

Misc

  • Changelog
  • Support
  • Flexpa OS
  • We're hiring

Flexpa Node SDK

The Flexpa Node SDK is a TypeScript library that provides a simple way to interact with the Flexpa API and FHIR API. It provides a set of methods to perform the token exchange, introspect, refresh, and revoke the access token. It also provides methods to interact with the FHIR API, such as reading, searching, and retrieving all the resources for the patient.

#Prerequisites

To use the Flexpa Node SDK, you must have NodeJs version 18 or higher installed on your machine. You can download NodeJs from the official website.

#Installation

To install the Flexpa Node SDK, run this command in your terminal.

Install SDK

yarn install @flexpa/node-sdk

#Getting Started

After installing the package, import it into your project to start using the FlexpaClient.

Import FlexpaClient

import FlexpaClient from '@flexpa/node-sdk';

#Initialize

You have a few different options for initializing the FlexpaClient, depending on your use case:

If you already have a workflow set up to obtain an access token and you simply want to use the FlexpaClient to call our APIs, please use the fromBearerToken function.

If you'd like to use the FlexpaClient to assist with the full token exchange process and work within a patient context, please use the fromExchange function. This will ultimately provide you with an access token that you can use to call our APIs.

If you need to make server-to-server API calls without a patient context, please use the fromClientCredentials function. This will provide you with an application access token valid for 30 minutes.

All methods will provide a FlexpaClient that you can use to interact with the Flexpa APIs. Once the FlexpaClient is initialized, you can use it to call the Flexpa APIs, such as the Link API and the FHIR API.

#fromBearerToken

Initialize a FlexpaClient from a given access token. This is the recommended way to initialize the FlexpaClient if you already have an access token and need to call the Flexpa APIs.

Parameters

bearerTokenstringRequired

Access token

apiBaseUrlstring

Flexpa API endpoint (default: https://api.flexpa.com)

From Bearer Token

const flexpaClient = FlexpaClient.fromBearerToken('your-access-token');

#fromExchange

Initialize a FlexpaClient from the token that is received after performing the Exchange step. This is the recommended way to initialize the FlexpaClient if you need to perform the token exchange and then call the Flexpa APIs.

Parameters

publicTokenstringRequired

Public Token

secretKeystringRequired

Secret Key

apiBaseUrlstring

Flexpa API endpoint (default: https://api.flexpa.com)

From Exchange

const flexpaClient = await FlexpaClient.fromExchange(
  'your-public-token',
  'your-secret-key'
);

#fromClientCredentials

Initialize a FlexpaClient using the OAuth 2.0 Client Credentials flow to obtain an application access token. This method is designed for server-to-server authentication without a patient context.

Application access tokens are valid for 30 minutes (1800 seconds), use JWT format with ES256 signatures, and don't require a patient context.

Note: Application access tokens can only be created using live mode API keys. If you use test mode keys, the request will be rejected with a 403 error.

Parameters

publishableKeystringRequired

Publishable Key. See API Keys.

secretKeystringRequired

Secret Key. See API Keys.

apiBaseUrlstring

Flexpa API endpoint (default: https://api.flexpa.com)

From Client Credentials

const flexpaClient = await FlexpaClient.fromClientCredentials(
  'your-publishable-key',
  'your-secret-key'
);

#Link API

#exchange

Perform the token exchange.

Parameters

publicTokenstringRequired

Public Token

secretKeystringRequired

Secret Key

Exchange

await flexpaClient.exchange(
  'your-public-token',
  'your-secret-key'
);

#introspect

Retrieve details about the access token

Introspect

const flexpaClient = await FlexpaClient.fromExchange(
  'your-public-token',
  'your-secret-key'
);
const tokenDetails = await flexpaClient.introspect('your-access-token');

#tokenRefresh

Refresh the access token. This method is only supported for MULTIPLE usage patient authorizations.

Parameters

publishableKeystringRequired

Publishable Key

secretKeystringRequired

Secret Key

Token Refresh

const flexpaClient = await FlexpaClient.fromExchange(
  'your-public-token',
  'your-secret-key'
);
const newAccessTokenData = await flexpaClient.refresh(
  'your-publishable-key', 
  'your-secret-key'
);

#revoke

Revoke the access token

Parameters

secretKeystringRequired

Secret Key

Revoke

const flexpaClient = await FlexpaClient.fromExchange(
  'your-public-token',
  'your-secret-key'
);
await flexpaClient.revoke('your-access-token');

#FHIR API

#getCapabilityStatement

Retrieve the FHIR capability statement

Get Capability Statement

const flexpaClient = await FlexpaClient.fromExchange(
  'your-public-token',
  'your-secret-key'
);
const capabilityStatement = await flexpaClient.getCapabilityStatement();

#read

Read a FHIR resource

Parameters

resourceTypestringRequired

Supported FHIR Resource

idstringRequired

Resource ID

numRetriesnumber

Number of retries (default: 10)

delayMsnumber

Delay in milliseconds (default: 1000)

Read

const flexpaClient = await FlexpaClient.fromExchange(
  'your-public-token',
  'your-secret-key'
);
const patient = await flexpaClient.read('Patient', 'patient-id');

#search

Search a FHIR resource

Parameters

resourceTypestringRequired

Supported FHIR Resource

searchParamsDictionaryRequired

Dictionary of search parameters

numRetriesnumber

Number of retries (default: 10)

delayMsnumber

Delay in milliseconds (default: 1000)

Search

const flexpaClient = await FlexpaClient.fromExchange(
  'your-public-token',
  'your-secret-key'
);
const patients = await flexpaClient.search('Patient',
  { given: 'John' }
);
const observations = await flexpaClient.search('Observation',
  { patient: 'patient-id' }
);

#Patient $everything

Retrieve all the resources for the patient

$everything

const flexpaClient = await FlexpaClient.fromExchange(
  'your-public-token',
  'your-secret-key'
);
const patientData = await flexpaClient.$everything();

#Utilities

#getAccessToken

Retrieve the access token

Get Access Token

const flexpaClient = await FlexpaClient.fromExchange(
  'your-public-token',
  'your-secret-key'
);
const accessToken = flexpaClient.getAccessToken();
Status TwitterGitHub

© 2025 Flexpa. All rights reserved.