The Public API Software Development Kit (SDK) provides you with the tools you need to integrate with Narmi's platform quickly and efficiently.
Currently, our SDK supports TypeScript and Node.js. Contact support@narmi.com to request support in other languages.
Getting Started
Follow these instructions to get started with our SDK:
1. Email support@narmi.com to request necessary testing data, including:
- Test user credentials: a
usernameand apassword - OAuth-application credentials; a
CLIENT_SECRET,CLIENT_ID, and aREDIRECT_URI - Sandbox server information; the
AUTH_URLand theAPI_URL
2. Download your target build from the (releases tag)[https://github.com/narmi/public-api-sdk-ts/releases]
Note: Alternatively, you can clone via git clone git@github.com:narmi/public-api-sdk-ts.git but this requires you to install and run the openapi-generator yourself.
3. unzip and cd into the project directory
$ unzip public-api-sdk-ts-<release_name>.zip
$ cd public-api-sdk-ts
4. Install Node.js v22.4.1. This should include npm, but if not, also install npm@v10.8.2.
5. Create an .env file in the root directory and set values provided by Narmi, as well as a PORT. Paste the following variables into your .env file:
CLIENT_ID= oauth client id
CLIENT_SECRET= oauth client secret
REDIRECT_URI= url to redirect to during oauth2 flow
AUTH_URL= url to the oauth2 authentication endpoint
API_URL= url to the hosted api instance
PORT=3000
6. Install dependencies
npm install --include=dev
Note: If you've cloned the repository, you'll need to generate the SDK yourself. To do this:
- Download the openapi yaml file corresponding to the version of the API you are implementing via
curl -o public.yml "https://apidocs-narmi.s3.amazonaws.com/public/public-<release-version>.yml" - Ensure you have Java v17 installed on your development computer.
- Run
npm run generate-sdk - There may be a few benign errors during SDK generation; if any of them lead to issues using the SDK, please email support@narmi.com.
7. Build the test app
npm run build
8. Start the test app
npm start
9. Navigate to the test app login page http://localhost:3000/login and log in using the testuser account.
You should now be able to see the running test app pull data from the Narmi Public API.
How It Works
The generated API creates a series of classes representing each tag of the documentation at https://online.sandbox.narmi.dev/v1/docs as an API.
For instance, https://online.sandbox.narmi.dev/v1/docs#tag/accounts becomes:
import * as publicApiSDK from "../sdk/index";
let apiClass = publicApiSDK.AccountsApi
Each API must be provided with a configuration object when instantiated for authentication purposes. A utility has been defined at public-api-sdk/src/utils.ts to make this easier:
let api = new publicApiSDK.AccountsApi(publicApiSDK.getConfiguration(access_token, header_secret))
Each API method is defined to represent an operation id from the documentation, so https://online.sandbox.narmi.dev/v1/docs#tag/accounts/operation/accounts_list becomes accountsList:
let response = await api.accountsList()
Responses will be promises resolving to typed data structures, allowing typescript compatible linters to assist you with interacting with them. In the event of an error response, the SDK will throw an error instead of returning the unadultered response, so it's best to try/catch:
try {
let response = await api.accountsRetrieve({"uuid": req.params.accountId})
res.render("account", response)
} catch(e) {
utils.handleError(e, res)
}
These examples are taken from public-api-sdk/src/test-express-app/index.ts, which powers the introductory application.