docparser-node
v1.2.2
Published
Docparser API Node Client
Downloads
852
Readme
Documentation
For a generic description of the Docparser API, please see our developer documentation here. Our developer documentation lists all available API methods with their parameters and expected responses.
Installation
This library is available from npm.
npm install docparser-node
Configuration
Create a Docparser JavaScript Client by using your Docparser API Token:
var docparser = require('docparser-node');
var client = new docparser.Client("validAPIKey");
Test Your Authentication
You can call our ping()
method to test your API key. The method retuns a promise.
client.ping()
.then(function() {
console.log('authentication succeeded!')
})
.catch(function(err) {
console.log('authentication failed!')
})
Usage
Document Parsers
List All Document Parsers Returns a list of the document parsers created in your account.
client.getParsers()
.then(function (parsers) {
console.log(parsers)
// => [{"id":"someparserid","label":"My Document Parser"}]
})
.catch(function (err) {
console.log(err)
})
Documents
The Docparser JavaScript SDK offers two different methods for importing your document.
All import methods allow you to pass an optional remote_id
with your document. The remote ID can be any arbitrary string with a maximum length of 255 characters. The submitted value will be kept throughout the processing and will be available later once you obtain the parsed data with our API or through Webhooks. The remote_id
can be passed in the options
object to our upload methods.
The upload methods (uploadByPath
, uploadByStream
) allow you to override the filename by specifying the filename
parameter in options
.
Upload Document From Local File System
Reads a file from your local filesystem and uploads it to your document parser.
client.uploadFileByPath('someparserid', './test.pdf', {remote_id: 'test'})
.then(function (result) {
// => {"id":"document_id","file_size":198989,"quota_used":16,"quota_left":34,"quota_refill":"1970-01-01T00:00:00+00:00"}
})
.catch(function (err) {
console.log(err)
})
Upload Document From A Readable Stream
This method creates a new document in your document parser based on the raw file content or a file pointer. Additionally, a filename
and a remote_id
can be provided in the options object.
client.uploadFileByStream('someparserid', fs.createReadStream('filepath'), options)
.then(function (result) {
// => {"id":"document_id","file_size":198989,"quota_used":16,"quota_left":34,"quota_refill":"1970-01-01T00:00:00+00:00"}
})
.catch(function (err) {
console.log(err)
})
Fetch Document From An URL
Imports a document from a publicly available HTTP(S) URL.
client.fetchDocumentFromURL('someparserid', 'http://example.com/test.pdf', {remote_id: 'test'})
.then(function (result) {
// => {"id":"document_id","file_size":153914,"quota_used":17,"quota_left":33,"quota_refill":"1970-01-01T00:00:00+00:00"}
})
.catch(function (err) {
console.log(err)
})
Parsed Data
The Docparser API allows you to retrieve the extracted document data. You can either list the data of multiple documents or get the data of a specific document.
Both methods used for retrieving parsed data allow you to specify the "format" parameter - this allows you to choose between a flat structure and a nested array structure. For most implementations, leaving it as "object" will serve you fine.
Please note: Polling the API for new results is not the recommended way of obtaining your data. A much better way than polling our API for parsed data is to use Webhooks. By using webhooks, parsed data will be pushed to your API immediately after parsing.
Get Data Of One Document
Fetches the parsed data for a specific document by providing a parserId
and the documentId
. The documentId
is the Docparser Document ID which is returned when importing a document through the API.
client.getResultsByDocument(parserId, documentId, {format: 'object'})
.then(function (result) {
console.log(result)
})
.catch(function (err) {
console.log(err)
})
Get Data Of Multiple Documents
Fetches the results of multiple documents parsed by a specific document parser. This function allows you granular filtering and ordering of the results. Please see our documentation for the list of available parameters.
client.getResultsByParser(parserId, {format: 'object'})
.then(function (result) {
console.log(result)
})
.catch(function (err) {
console.log(err)
})
Contributing
Bug reports and pull requests are welcome on GitHub.
Please follow Standard Code Style with your contributions. You can check for code style by running npm test
when developing this library.
License
The library is available as open source under the terms of the MIT License.
The MIT License (MIT)
Copyright (c) 2016 DAUSINGER DIGITAL EURL.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Changelog
- 11/16/2017 initial release