npm install omeda-api-client --save
const omedaApi = require('omeda-api-client')({
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 = require('omeda-api-client');
const fooBrand = omedaFactory({ brandKey: 'foo' /* additional options */ });
const barBrand = omedaFactory({ brandKey: 'bar' /* additional options */ });
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 = require('omeda-api-client')(/* options */);
const customer = omedaApi.resources.customer;
customer.lookupByEmail('[email protected]')
.then(data => console.info(data))
.catch(err => console.info('An error was found!', err))
;
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('[email protected]')
from above:
const omedaApi = require('omeda-api-client')(/* options */);
omedaApi.request('brand', 'GET', '/customer/email/[email protected]/*').then(/* ... */);
Access the resource:
const omedaApi = require('omeda-api-client')(/* options */);
const customer = omedaApi.resources.customer;
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.lookup(1013321055).then().catch()
customer.lookupByEmail(email, [productId])
Performs a Customer Lookup By Email. Can optionally limit the result to a specified product ID.
customer.lookupByEmail('[email protected]').then().catch()
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.lookupByEncryptedId('1773F6238056C8U').then().catch()
customer.lookupByExternalId(namespace, externalId)
Performs a Customer Lookup Service By External ID.
customer.lookupByExternalId('some-namespace', 'some-external-id').then().catch()
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.lookupById(1013321055).then().catch()
customer.save(payload)
Saves (creates/updates) a customer and/or order via the Save Customer and Order API.
customer.save({ payload }).then().catch()
Access the resource:
const omedaApi = require('omeda-api-client')(/* options */);
const brand = omedaApi.resources.brand;
brand.lookup()
Performs a Brand Comprehensive Lookup.
brand.lookup().then().catch()
- Clone this repository
- Install dependencies using Yarn
cd omeda-api-client
yarn install
- Execute
npm run test
- To see code coverage, run
npm run coverage
- Ensure that both the
npm run lint
andnpm run test
commands are successful before PRing. - Preferably, code coverage should remain unchanged (or become better).