4.3.0 • Published 4 years ago

onfido v4.3.0

Weekly downloads
980
License
MIT
Repository
-
Last release
4 years ago

onfido

Onfido - JavaScript client for onfido The Onfido API is used to submit check requests.

This package is automatically generated by the OpenAPI Generator project:

  • API version: 2.0.0
  • Package version: 4.3.0
  • Build package: org.openapitools.codegen.languages.JavascriptClientCodegen

Installation

For Node.js

Install via npm:

npm install onfido

Alternatively, if you're using Yarn:

yarn add onfido

Frontend JavaScript: warning

You must not use this project in your application's frontend because it uses API tokens. Instead, you can use the Onfido Web SDK for frontend JavaScript.

If you use this project in your frontend, malicious users could discover the tokens in your source code. You should only use this project in your backend code.

You can read more about API token security in the Onfido API reference documentation.

Getting Started

Please follow the installation instruction and execute the following JS code:

const Onfido = require('onfido');

const defaultClient = Onfido.ApiClient.instance;

// Configure API key authorization: Token
const token_auth = defaultClient.authentications['Token'];
token_auth.apiKey = 'token=' + 'YOUR API KEY';
token_auth.apiKeyPrefix = 'Token';

// Limit the at-rest region, if needed (optional, see https://documentation.onfido.com/#regions)
// defaultClient.basePath = Onfido.ApiClient.getBasePathFromSettings(1, {region: 'us'});

const api = new Onfido.DefaultApi();

// Setting applicant details
const applicant = new Onfido.Applicant();
applicant.first_name = 'John';
applicant.last_name = 'Smith';
applicant.dob = new Date('1980-01-22');
applicant.country = 'GBR';

// You can also use getters and setters for properties using camelCase:
// applicant.setFirstName('John');
// applicant.setLastName('Smith');

const address = new Onfido.Address();
address.building_number = '100';
address.street = 'Main Street';
address.town = 'London';
address.postcode = 'SW4 6EH';
address.country = 'GBR';

applicant.addresses = [address];

// Setting check details
const check = new Onfido.Check();
check.type = 'express';
const report = new Onfido.Report();
report.name = 'identity';
check.reports = [report];

// Using promises
api.createApplicant(applicant).then(applicantData => {
  const applicantId = applicantData.id;
  return api.createCheck(applicantId, check);
}).then(checkData => {
  console.log(checkData);
}).catch(error => {
  console.error(error.response.body);
});

// Using async/await
(async () => {
  try {
    const applicantData = await api.createApplicant(applicant);
    const applicantId = applicantData.id;
    const checkData = await api.createCheck(applicantId, check);
    console.log(checkData);
  } catch(error) {
    console.error(error.response.body);
  }
})();

Uploading and Downloading

For uploading files, the file argument should be a Readable Stream. For example, for uploading a document:

const documentImage = fs.createReadStream('document.png');
api.uploadDocument(applicantId, 'passport', documentImage);

There is currently an issue with OpenAPI Generator, the tool used to generate this library, that prevents downloading files from working in Node. As a workaround, you can use the API endpoints for downloading files directly. See the API documentation for more info:

Documentation for API Endpoints

All URIs are relative to https://api.onfido.com/v2

ClassMethodHTTP requestDescription
Onfido.DefaultApicancelReportPOST /checks/{check_id}/reports/{report_id}/cancelThis endpoint is for cancelling individual paused reports.
Onfido.DefaultApicreateApplicantPOST /applicantsCreate Applicant
Onfido.DefaultApicreateCheckPOST /applicants/{applicant_id}/checksCreate a check
Onfido.DefaultApicreateWebhookPOST /webhooksCreate a webhook
Onfido.DefaultApideleteWebhookDELETE /webhooks/{webhook_id}Delete a webhook
Onfido.DefaultApidestroyApplicantDELETE /applicants/{applicant_id}Delete Applicant
Onfido.DefaultApidownloadDocumentGET /applicants/{applicant_id}/documents/{document_id}/downloadDownload a documents raw data
Onfido.DefaultApidownloadLivePhotoGET /live_photos/{live_photo_id}/downloadDownload live photo
Onfido.DefaultApidownloadLiveVideoGET /live_videos/{live_video_id}/downloadDownload live video
Onfido.DefaultApieditWebhookPUT /webhooks/{webhook_id}Edit a webhook
Onfido.DefaultApifindAddressesGET /addresses/pickSearch for addresses by postcode
Onfido.DefaultApifindApplicantGET /applicants/{applicant_id}Retrieve Applicant
Onfido.DefaultApifindCheckGET /applicants/{applicant_id}/checks/{check_id}Retrieve a Check
Onfido.DefaultApifindDocumentGET /applicants/{applicant_id}/documents/{document_id}A single document can be retrieved by calling this endpoint with the document’s unique identifier.
Onfido.DefaultApifindLivePhotoGET /live_photos/{live_photo_id}Retrieve live photo
Onfido.DefaultApifindLiveVideoGET /live_videos/{live_video_id}Retrieve live video
Onfido.DefaultApifindReportGET /checks/{check_id}/reports/{report_id}A single report can be retrieved using this endpoint with the corresponding unique identifier.
Onfido.DefaultApifindReportTypeGroupGET /report_type_groups/{report_type_group_id}Retrieve single report type group object
Onfido.DefaultApifindWebhookGET /webhooks/{webhook_id}Retrieve a Webhook
Onfido.DefaultApigenerateSdkTokenPOST /sdk_tokenGenerate a SDK token
Onfido.DefaultApilistApplicantsGET /applicantsList Applicants
Onfido.DefaultApilistChecksGET /applicants/{applicant_id}/checksRetrieve Checks
Onfido.DefaultApilistDocumentsGET /applicants/{applicant_id}/documentsList documents
Onfido.DefaultApilistLivePhotosGET /live_photosList live photos
Onfido.DefaultApilistLiveVideosGET /live_videosList live videos
Onfido.DefaultApilistReportTypeGroupsGET /report_type_groupsRetrieve all report type groups
Onfido.DefaultApilistReportsGET /checks/{check_id}/reportsAll the reports belonging to a particular check can be listed from this endpoint.
Onfido.DefaultApilistWebhooksGET /webhooksList webhooks
Onfido.DefaultApirestoreApplicantPOST /applicants/{applicant_id}/restoreRestore Applicant
Onfido.DefaultApiresumeCheckPOST /checks/{check_id}/resumeResume a Check
Onfido.DefaultApiresumeReportPOST /checks/{check_id}/reports/{report_id}/resumeThis endpoint is for resuming individual paused reports.
Onfido.DefaultApiupdateApplicantPUT /applicants/{applicant_id}Update Applicant
Onfido.DefaultApiuploadDocumentPOST /applicants/{applicant_id}/documentsUpload a document
Onfido.DefaultApiuploadLivePhotoPOST /live_photosUpload live photo

Documentation for Models

Documentation for Authorization

Token

  • Type: API key
  • API key parameter name: Authorization
  • Location: HTTP header
4.3.0

4 years ago

4.2.0

5 years ago

4.1.0

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.0.1

5 years ago

2.1.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

2.0.0

5 years ago

1.0.1

7 years ago