Giter Club home page Giter Club logo

api-javascript-client's Introduction

⚠️ Please use onfido-node instead ⚠️

This library has been superseded by onfido-node

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

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

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

Documentation for Authorization

Token

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

api-javascript-client's People

Contributors

alanjc7 avatar ciaran16 avatar hjheath avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

api-javascript-client's Issues

Getting Incorrect file type

Am building a verification system using Onfido with NodeJS.

After creating an applicant and running checks, I get incorrect file type anytime I am uploading a file using the uploadDocument method of this sdk.

var applicant_id = req.body.applicant_id;

   var type = 'passport';
  var opts = {
	side: 'front',
	file: req.file.path
};
 console.log(opts['file']);
api.uploadDocument(applicant_id, type, opts, function (err, data, response) {
// console.log('Err', err);
// console.log('Data', data);
 console.log('Response', response);
})

Response Output
image

Please, what is the solution to this issue?

Warm Regards,
Isaac.

I can't use API in NodeJs project

I have created a new project with NodeJs and run '''npm install onfido''' but when I use '''const Onfido = require('onfido');''' I have the error "Module not found".

This error also appears in a new React project.

Dependencies not found

I am seeing the following when trying to use onfido with Vue.js:

web_1  | yarn run v1.7.0
web_1  | $ vue-cli-service serve
web_1  |  INFO  Starting development server...
web_1  |  94% after seal ERROR  Failed to compile with 24 errors2:23:24 PM
web_1  |
web_1  | These dependencies were not found:
web_1  |
web_1  | * ApiClient in ./node_modules/onfido/src/index.js
web_1  | * api/DefaultApi in ./node_modules/onfido/src/index.js
web_1  | * models/Address in ./node_modules/onfido/src/index.js
web_1  | * models/Applicant in ./node_modules/onfido/src/index.js
web_1  | * models/ApplicantsList in ./node_modules/onfido/src/index.js
web_1  | * models/Check in ./node_modules/onfido/src/index.js
web_1  | * models/CheckCreationRequest in ./node_modules/onfido/src/index.js
web_1  | * models/ChecksList in ./node_modules/onfido/src/index.js
web_1  | * models/Document in ./node_modules/onfido/src/index.js
web_1  | * models/DocumentsList in ./node_modules/onfido/src/index.js
web_1  | * models/Error in ./node_modules/onfido/src/index.js
web_1  | * models/GenericAddress in ./node_modules/onfido/src/index.js
web_1  | * models/GenericAddressesList in ./node_modules/onfido/src/index.js
web_1  | * models/IdNumber in ./node_modules/onfido/src/index.js
web_1  | * models/LivePhoto in ./node_modules/onfido/src/index.js
web_1  | * models/LivePhotosList in ./node_modules/onfido/src/index.js
web_1  | * models/Report in ./node_modules/onfido/src/index.js
web_1  | * models/ReportType in ./node_modules/onfido/src/index.js
web_1  | * models/ReportTypeGroup in ./node_modules/onfido/src/index.js
web_1  | * models/ReportTypeGroupsList in ./node_modules/onfido/src/index.js
web_1  | * models/ReportTypeOption in ./node_modules/onfido/src/index.js
web_1  | * models/ReportsList in ./node_modules/onfido/src/index.js
web_1  | * models/Webhook in ./node_modules/onfido/src/index.js
web_1  | * models/WebhooksList in ./node_modules/onfido/src/index.js

I have tried installing via the npm onfido and onfido/api-javascript-client methods, but both produce this issues.

Issue while downloading file from onfido using api endpoints as suggested in the document

I am trying to download the file from Node.js using api endpoints with this endpoint https://api.onfido.com/v2/applicants/{applicant_id}/documents/{document_id}/download
but rather than getting binary value of the file, i am getting content in xmp adobe format which is corrupting the downloaded files. how can i solve this issue. I have attached the file with the content that i am getting from the onfdio. Please suggest
kyc_doc_141982e4-be4c-4040-bd60-c9005c288138_front-passport-shrawan

Download document returning "File is not defined"

Currently using firebase's node js cloud servers and want to download images of documents to my own storage to later show user. Yet when I try to download the image from onfido js-client I get an error saying "File is not defined". Any idea why? I am new to node.js and backend should I be parsing the return object to a certain type of file ??

Upload a live video

Is it possible to use this library to upload an example live video?

The documentation only refers to documents, is there support for video?

Thanks

Typescript integration?

Hi,

We intend to include Onfido in the onboarding process of our mobile app. We've received some API tokens and already started to fiddle with the tool. We would like to use your Javascript client library in our code in order to kick off the integration.

Our problem is that we're using NodeJs with Typescript, and that we can't find a .d.ts file that declare the types used in this library.

I know that the different client libraries were automatically generated through OpenAPIGenerator and that Typescript generation is supported by their tool. Would it be possible to create a Typescript version of your api client? I hope that would be more reasonable than ask to actually write a .d.ts file for the pure Javascript client (I can tell you, I just tried :) )

Thank you!

[BUG] CheckCreationRequest.reportTypeGroups is sending malformed data in body.

What I'm trying to do is create a check using a report type group.

I'm doing the following:

const checkCreationRequest = new onfido.CheckCreationRequest()
checkCreationRequest.type = 'standard'
checkCreationRequest.reportTypeGroups = [1234]

const opts = {
            data: checkCreationRequest
        }

api.createCheck(applicantId, opts, callback)

This fails on the server with:

{
  error: {
    type: 'validation_error',
    message: 'There was a validation error on this request',
    fields: {
      base: [
        Array
      ]
    }
  }
}

When I debug the code I see that the issue is the sdk sends the request body like this:

{
  "type": "standard",
  "reportTypeGroups": [1234]
}

When I change this line:
checkCreationRequest.reportTypeGroups =[1234]
to
checkCreationRequest.report_type_groups =[1234]

everything works.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.