cp-apis v1.0.0
cp-apis
CpApis - JavaScript client for cp-apis Public Rest API documentation for KYC REST API This SDK is automatically generated by the OpenAPI Generator project with some customization:
- API version: 1.2.1
- Package version: 1.2.1
- Build package: org.openapitools.codegen.languages.JavascriptClientCodegen
Installation
For Node.js
npm
To publish the library as a npm, please follow the procedure in "Publishing npm packages".
Then install it via:
npm install cp-apis --save
Finally, you need to build the module:
npm run build
Local development
To use the library locally without publishing to a remote npm registry, first install the dependencies by changing into the directory containing package.json
(and this README). Let's call this JAVASCRIPT_CLIENT_DIR
. Then run:
npm install
Next, link it globally in npm with the following, also from JAVASCRIPT_CLIENT_DIR
:
npm link
To use the link you just defined in your project, switch to the directory you want to use your cp-apis from, and run:
npm link /path/to/<JAVASCRIPT_CLIENT_DIR>
Finally, you need to build the module:
npm run build
git
If the library is hosted at a git repository, e.g.https://github.com/GIT_USER_ID/GIT_REPO_ID then install it via:
npm install GIT_USER_ID/GIT_REPO_ID --save
For browser
The library also works in the browser environment via npm and browserify. After following
the above steps with Node.js and installing browserify with npm install -g browserify
,
perform the following (assuming main.js is your entry file):
browserify main.js > bundle.js
Then include bundle.js in the HTML pages.
Webpack Configuration
Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:
module: {
rules: [
{
parser: {
amd: false
}
}
]
}
Getting Started
Please follow the installation instruction and execute the following JS code:
var CpApis = require('cp-apis');
const client = CpApis.ApiClient.instance({
basePath: "YOUR BASE PATH",
apiKey: "YOUR API KEY",
identityPoolId: "YOUR IDENTITY POOL ID",
branch: "YOUR BRANCH ID", // Optional: Set if you're a company with one branch or all data should exist in one location
});
var api = new CpApis.AccountsApi()
var uuid = "uuid_example"; // {String} The user UUID
api.getAccountSummary(uuid).then(function(data) {
console.log('API called successfully. Returned data: ' + data);
}, function(error) {
console.error(error);
});
Document Processing
- Initialize the sdk with the base path, api key and identity pool id assigned to you, and create a client. Also initialize the accounts and urls api using the client created.
var CpApis = require('cp-apis');
const client = CpApis.ApiClient.instance({
basePath: "YOUR BASE PATH",
apiKey: "YOUR API KEY",
identityPoolId: "YOUR IDENTITY POOL ID",
branch: "YOUR BRANCH ID", // Optional: Set if you're a company with one branch or all data should exist in one location
});
const urlsApi = new CpApis.UrlsApi(client);
const accountsApi = new CpApis.AccountsApi(client);
- Create a user to group documents in the QKYC system. An optional uuid will be used to identify the customer id to reflect that of another system.
const accountsApi = new CpApis.AccountsApi(client);
const { data } = await accountsApi.postAccount();
// Where data contains uuid, account information and credential information
Ensure that you store the uuid created during the account creation.
const { uuid } = data;
- Using a given schema uuid (uuid representing a group of documents; eg Proof of Identity) and a given credential uuid (represting a type of document; eg Driver's License) and the mime type for the document/image create a signed url to upload the document for processing.
const credentialUuid = "49c39635-4afc-45ce-a089-940ee58a1a9a";
const mime = "image/png";
const schemaUuid = "5296ee21-6597-475b-a2ff-8484bf0a10c4";
// Obtain the signed credential
const signedCredential = await urlsApi.getSignedCredentialUrls(credentialUuid, mime, schemaUuid, uuid);
// If a branch ID wasn't supplied on initialisation of the API, you need to add the branch to the signed credential
// eg. const signedCredential = await urlsApi.getSignedCredentialUrls(credentialUuid, mime, schemaUuid, uuid, { branch: 'Your branch ID' });
// For each page returned, upload an image to the path given using a put request
signedCredential.data.pages.forEach(page => {
const { label, url: { path } } = page;
// A label is given for each page to identity the side of document (Front/Back, Page1/Page2, etc);
// Using path, send a PUT request to the path containing the document
// We recommed using a plugin such as https://github.com/tus/tus-js-client to upload the files directly and resume when interrupted.
});
- Poll for changes at a reasonable interval to ensure that the document / documents were completed.
// Poll the summary api every 15s
const interval = setInterval(handleGetSummary, 15000);
async function handleGetSummary() {
const summary = await accountsApi.getAccountSummary(uuid);
console.log(summary);
// Poll until the credentials are recognised and there are no more processing documents
if (summary.data && !summary.data.processing && summary.data.credentials) {
clearInterval(interval);
}
};
For this example polling will produce results similar to this:
{
"data": {
"processing": 0,
"approved": 0,
"rejected": 0,
"credentials": [
{
"label": "Drivers Permit",
"credentialUuid": "49c39635-4afc-45ce-a089-940ee58a1a9a",
"schemaUuid": "5296ee21-6597-475b-a2ff-8484bf0a10c4",
"processing": false,
"approved": false,
"rejected": false,
"pages": [
{
"label": "Front",
"fields": {
"address": {
"value": "****",
"accuracy": "1.0",
"required": true
},
"issueDate": {
"value": "****",
"accuracy": "1.0",
"required": false
},
"dateOfPayment": {
"value": "****",
"accuracy": "1.0",
"required": false
},
"dateOfBirth": {
"value": "****",
"accuracy": "1.0",
"required": true
},
"sex": {
"value": "****",
"accuracy": "1.0",
"required": false
},
"name": {
"value": "****",
"accuracy": "1.0",
"required": true
},
"dpExpiryDate": {
"value": "****",
"accuracy": "1.0",
"required": true
},
"dpNumber": {
"value": "****",
"accuracy": "1.0",
"required": false
},
"class": {
"value": "****",
"accuracy": "1.0",
"required": false
}
}
}
]
}
]
},
"statusCode": "200"
}
- Login to the QKYC admin app to review the document and approve.
Documentation for API Endpoints
Class | Method | HTTP request | Description |
---|---|---|---|
CpApis.AccountsApi | getAccountSummary | GET /accounts/public/{uuid}/summary | Gets a summary of the credentials associated to a user |
CpApis.AccountsApi | postAccount | POST /accounts/public | Allows public user to upload their account information when creating a new account |
CpApis.AccountsApi | putAccount | PUT /accounts/public/{uuid} | Allows public user to update their account information during their flow |
CpApis.DefaultApi | getAppConfig | GET /util/app_config | Public endpoint to get an app configuration |
CpApis.DevicesApi | postDevice | POST /devices/public | Public endpoint to update or create a device for a user using an api key |
CpApis.RequestsApi | getWebRequestByUuid | GET /requests/web/{uuid} | Get the request data sent to a user |
CpApis.UrlsApi | getSignedBlinkDetectionUrl | GET /urls/public/signed_blink_detection | Public endpoint to obtain a signed url to upload a blink detection video to our storage service |
CpApis.UrlsApi | getSignedCredentialUrls | GET /urls/public/signed_credential | Public endpoint to obtain a signed urls to upload credential images to our storage service |
CpApis.UrlsApi | getSignedUploadUrl | GET /urls/public/signed_upload_url | Public endpoint to obtain a signed url to upload any file type to our storage service |
ApiKeyAuth
- Type: API key
- API key parameter name: x-api-key
- Location: HTTP header