onfido
v4.3.0
Published
Client library for the Onfido API.
Downloads
696
Readme
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:
- Documents: https://documentation.onfido.com/#download-document
- Live Photos: https://documentation.onfido.com/#download-live-video
Documentation for API Endpoints
All URIs are relative to https://api.onfido.com/v2
Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- Onfido.DefaultApi | cancelReport | POST /checks/{check_id}/reports/{report_id}/cancel | This endpoint is for cancelling individual paused reports. Onfido.DefaultApi | createApplicant | POST /applicants | Create Applicant Onfido.DefaultApi | createCheck | POST /applicants/{applicant_id}/checks | Create a check Onfido.DefaultApi | createWebhook | POST /webhooks | Create a webhook Onfido.DefaultApi | deleteWebhook | DELETE /webhooks/{webhook_id} | Delete a webhook Onfido.DefaultApi | destroyApplicant | DELETE /applicants/{applicant_id} | Delete Applicant Onfido.DefaultApi | downloadDocument | GET /applicants/{applicant_id}/documents/{document_id}/download | Download a documents raw data Onfido.DefaultApi | downloadLivePhoto | GET /live_photos/{live_photo_id}/download | Download live photo Onfido.DefaultApi | downloadLiveVideo | GET /live_videos/{live_video_id}/download | Download live video Onfido.DefaultApi | editWebhook | PUT /webhooks/{webhook_id} | Edit a webhook Onfido.DefaultApi | findAddresses | GET /addresses/pick | Search for addresses by postcode Onfido.DefaultApi | findApplicant | GET /applicants/{applicant_id} | Retrieve Applicant Onfido.DefaultApi | findCheck | GET /applicants/{applicant_id}/checks/{check_id} | Retrieve a Check Onfido.DefaultApi | findDocument | GET /applicants/{applicant_id}/documents/{document_id} | A single document can be retrieved by calling this endpoint with the document’s unique identifier. Onfido.DefaultApi | findLivePhoto | GET /live_photos/{live_photo_id} | Retrieve live photo Onfido.DefaultApi | findLiveVideo | GET /live_videos/{live_video_id} | Retrieve live video Onfido.DefaultApi | findReport | GET /checks/{check_id}/reports/{report_id} | A single report can be retrieved using this endpoint with the corresponding unique identifier. Onfido.DefaultApi | findReportTypeGroup | GET /report_type_groups/{report_type_group_id} | Retrieve single report type group object Onfido.DefaultApi | findWebhook | GET /webhooks/{webhook_id} | Retrieve a Webhook Onfido.DefaultApi | generateSdkToken | POST /sdk_token | Generate a SDK token Onfido.DefaultApi | listApplicants | GET /applicants | List Applicants Onfido.DefaultApi | listChecks | GET /applicants/{applicant_id}/checks | Retrieve Checks Onfido.DefaultApi | listDocuments | GET /applicants/{applicant_id}/documents | List documents Onfido.DefaultApi | listLivePhotos | GET /live_photos | List live photos Onfido.DefaultApi | listLiveVideos | GET /live_videos | List live videos Onfido.DefaultApi | listReportTypeGroups | GET /report_type_groups | Retrieve all report type groups Onfido.DefaultApi | listReports | GET /checks/{check_id}/reports | All the reports belonging to a particular check can be listed from this endpoint. Onfido.DefaultApi | listWebhooks | GET /webhooks | List webhooks Onfido.DefaultApi | restoreApplicant | POST /applicants/{applicant_id}/restore | Restore Applicant Onfido.DefaultApi | resumeCheck | POST /checks/{check_id}/resume | Resume a Check Onfido.DefaultApi | resumeReport | POST /checks/{check_id}/reports/{report_id}/resume | This endpoint is for resuming individual paused reports. Onfido.DefaultApi | updateApplicant | PUT /applicants/{applicant_id} | Update Applicant Onfido.DefaultApi | uploadDocument | POST /applicants/{applicant_id}/documents | Upload a document Onfido.DefaultApi | uploadLivePhoto | POST /live_photos | Upload live photo
Documentation for Models
- Onfido.Address
- Onfido.Applicant
- Onfido.ApplicantsList
- Onfido.Check
- Onfido.CheckCommon
- Onfido.CheckWithReportIds
- Onfido.ChecksList
- Onfido.Document
- Onfido.DocumentsList
- Onfido.Error
- Onfido.GenericAddress
- Onfido.GenericAddressesList
- Onfido.IdNumber
- Onfido.LivePhoto
- Onfido.LivePhotosList
- Onfido.LiveVideo
- Onfido.LiveVideosList
- Onfido.Report
- Onfido.ReportDocument
- Onfido.ReportOption
- Onfido.ReportType
- Onfido.ReportTypeGroup
- Onfido.ReportTypeGroupsList
- Onfido.ReportsList
- Onfido.SdkTokenRequest
- Onfido.SdkTokenResponse
- Onfido.Webhook
- Onfido.WebhooksList
Documentation for Authorization
Token
- Type: API key
- API key parameter name: Authorization
- Location: HTTP header