Omeda API Client for NodeJS
Installing
npm install omeda-api-client --save
Usage
Create an API client instance
const omedaApi = brandKey: 'yourbrand' // your Omeda brand/db name clientKey: 'client_yourclient' // your Omeda client id appId: '1d381ff5-ba0b-47ce-8730-ce91b05f7b54' // your API app-id to access the brand inputId: 'XXXXXXX' // the API input-id to write data to the db useStaging: false // default, switch to true to access the staging db;
You can also create multiple instances of the API client to connect to different brand databases...
const omedaFactory = ; const fooBrand = ;const barBrand = ;
Making API calls
Once you have a client instance, you can begin making API calls. Each API "category" is organized into corresponding resources. For instance, "customer" related APIs can be accessed via the customer
resource; brand APIs can be accessed via the brand
resource, etc.
For example, to lookup a customer by email address, you would execute the following call:
const omedaApi = /* options */;const customer = omedaApiresourcescustomer; customer ;
All API resource functions will return a Promise
(specifically a bluebird
promise) via the request-promise library.
You can also make any number of "generic" API calls that may not be covered by this library, or if you're just feeling fancy :) This is the equivelant to calling customer.lookupByEmail('foo@bar.com')
from above:
const omedaApi = /* options */; omedaApi;
Complete API Reference
The Customer Resource
Access the resource:
const omedaApi = /* options */;const customer = omedaApiresourcescustomer;
customer.lookup(customerId, [returnMerged=true])
Performs a Comprehensive Customer Lookup. Will return the full details of the customer. By default, if the customer that was found was merged into another, it will return the merged version.
customer
customer.lookupByEmail(email, [productId])
Performs a Customer Lookup By Email. Can optionally limit the result to a specified product ID.
customer
customer.lookupByEncryptedId(encryptedId, [returnMerged = true])
Performs a Customer Lookup by EncryptedCustomerId. By default, if the customer that was found was merged into another, it will return the merged version.
customer
customer.lookupByExternalId(namespace, externalId)
Performs a Customer Lookup Service By External ID.
customer
customer.lookupById(customerId, [returnMerged = true])
Performs a Customer Lookup by CustomerId. By default, if the customer that was found was merged into another, it will return the merged version.
customer
customer.save(payload)
Saves (creates/updates) a customer and/or order via the Save Customer and Order API.
customer
The Brand Resource
Access the resource:
const omedaApi = /* options */;const brand = omedaApiresourcesbrand;
brand.lookup()
Performs a Brand Comprehensive Lookup.
brand
Developing / Contributing
- Clone this repository
- Install dependencies using Yarn
cd omeda-api-client
yarn install
Running tests
- Execute
npm run test
- To see code coverage, run
npm run coverage
Contributing
- Ensure that both the
npm run lint
andnpm run test
commands are successful before PRing. - Preferably, code coverage should remain unchanged (or become better).