collectid-api-client v1.0.18
CollectID Client Library SDK
A client SDK for Web and Node.js to interact with CollectID API.
API documentation: https://docs.collectid.io/v2
Installation
The CollectID Client Library SDK can be installed with npm:
npm install collectid-api-client
or yarn if you prefer:
yarn add collectid-api-client
Usage
Configure the SDK for your environment
The API client can be used in testing, staging and production environment.
For private endpoints, the JWT token needs to be provided via tokenProvider
.
For public endpoints, the TokenProvider
is optional.
import ApiClient from 'collectid-api-client';
import { TokenProviderFn } from './api-client';
const provideToken: TokenProviderFn = async () => {
// return the token from the Auth0 provider
return 'xxxxxxxxxxxx';
};
const apiClient = new ApiClient({
env: 'prod',
tokenProvider: provideToken,
})
Validate a Tag
To validate a tag, you can use the authenticateTag(tag: string)
method. The server shall
respond with successful response if the tag is valid, otherwise it will return an UnrecognizedTag
exception,
or EntityNotFound
exception.
apiClient.authenticateTag('1234567890')
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
Get the product information of the Tag
To get the product information of the tag, you can use the getProduct(tag: string, embed: string[])
method,
with the optional embeddable entities.
The library is written entirely in TypeScript. The allowed embeddable entities are checked by the typescript compiler, and the IDE will provide the list of available entities.
For example,
const product = apiClient.getProduct('<tagId>', ['cid:model', 'cid:brand']);
will return the product information with the model
and brand
entities embedded.
To retrieve the model
in the embedded section, use the following code:
const model = product.getEmbedded('cid:model');
This shall return the Embedded Model object with the relevant type information.
Features
The client SDK is currently only provide four methods to interact with the API server:
- Authenticate the Tag
getProduct()
method to retrieve product informationgetModel()
method to retrieve Model informationgetBrand()
method to retrieve Brand information
Todo:
- Add methods for all entities
- Other RESTful methods: POST, PUT, DELETE