A Node.js wrapper around the DocumentCloud API. Requires Node.js >= 4
.
npm install --save documentcloud
The client interface makes it possible to pass in your DocumentCloud username and password so you can do authenticated requests. While this is not required for some endpoints, your experience will likely be much better if you are authenticated.
// import the library
var DocumentCloudClient = require('documentcloud');
// create a client
var client = new DocumentCloudClient('username', 'password');
// get to work!
client.documents.get('1659580-economic-analysis-of-the-south-pole-traverse', function (err, response) {
if (err) throw err;
console.log(response);
});
// {
// "status_code": 200,
// "response": {
// "document": {
// "id": "1659580-economic-analysis-of-the-south-pole-traverse",
// "title": "Economic Analysis of the South Pole Traverse",
// "access": "public",
// "pages": 38,
// ...
The main DocumentCloud client. A DocumentCloud username and password are optional, but some methods are not available to unauthenticated users.
It is also possible to override the default base API URL.
Parameters
username
String= DocumentCloud username (optional, default null
)password
String= DocumentCloud password (optional, default null
)apiUrl
String= An override for
the DocumentCloud API base URL. (optional, default https://www.documentcloud.org/api/
)Examples
var DocumentCloudClient = require('documentcloud');
var client = new DocumentCloudClient('email@example.com', 'example_pw');
Handles all methods that interact with project API endpoints.
Should never be created manually — can be accessed on an instance of DocumentCloudClient
at DocumentCloudClient.projects
.
Parameters
client
Object Instance of DocumentCloudClientCreates a project.
Parameters
title
String Title of project.opts
Object= Additional parameters to be included with project creation
callback
Function Callback to handle API responseDeletes a project. Documents associated with the project are not effected.
Parameters
Lists all projects associated with the account.
Parameters
callback
Function Callback to handle API responseUpdates data associated with a project. Do note - this replaces every field,
whether it is provided or not. For example - if you do not provide a list of document_ids
,
it will be set to none.
Parameters
project_id
Number The project identifieropts
Object Parameters to be set during the update
callback
Function Callback to handle API responseHandles all methods that interact with document API endpoints.
Should never be created manually — can be accessed on an instance of DocumentCloudClient
at DocumentCloudClient.documents
.
Parameters
client
Object Instance of DocumentCloudClientDeletes a document on DocumentCloud.
Parameters
Returns a list of entities associated with a document.
Parameters
Get a document's metadata from DocumentCloud.
Parameters
Examples
client.documents.get('1659580-economic-analysis-of-the-south-pole-traverse', function (err, response) {
if (err) throw err;
console.log(response);
});
// {
// "status_code": 200,
// "response": {
// "document": {
// "id": "1659580-economic-analysis-of-the-south-pole-traverse",
// "title": "Economic Analysis of the South Pole Traverse",
// "access": "public",
// "pages": 38,
// ...
Searches the DocumentCloud service for documents.
Parameters
q
String The search queryopts
Object= Additional search parameters
opts.page
Number= Response page number (defaults to 1)opts.per_page
Number= The number of documents to return per page (defaults to 10, max is 1,000)opts.sections
Boolean= Include document sectionsopts.annotations
Boolean= Include document annotationsopts.data
Boolean= Include key/value data in resultsopts.mentions
Number= Include highlighted mentions of search phrase (none by default, max is 10)opts.order
String= Order documents are listed (defaults to created_at
, choices are: score
, created_at
, title
, page_count
, source
)callback
Function Callback that handles the API responseUpdate a document's title, source, description, related article, access
level, or data values. Values passed into opts
will be updated on the
requested document.
Parameters
doc_id
String Document identifieropts
Object Values to update
opts.title
String= Title of documentopts.source
String= Source of documentopts.description
String= Description of documentopts.related_article
String= URL of article associated with documentopts.published_url
String= URL of page where document will be embeddedopts.access
String= Sets access level (defaults to private
,
choices are: private
, public
, organization
) (optional, default private
)opts.data
Object= Object of key/value pairs to associate with documentcallback
Function Callback that handles the API responseUploads a document to DocumentCloud.
The file
can be a path to a document on disk, a Node.js Buffer, or the
URL to a public file.
Parameters
file
(String|Buffer) Path to a file, a Node.js Buffer, or public URLtitle
String Title of uploaded documentopts
Object= Additional parameters to be included with upload
opts.source
String= Source of documentopts.description
String= Description of documentopts.language
String= Language of document, will be used
determine which OCR package to be used (optional, default eng
)opts.related_article
String= URL of article associated with documentopts.access
String= Sets access level (defaults to private
,
choices are: private
, public
, organization
) (optional, default private
)opts.project
Number= Numeric ID of project to add document toopts.data
Object= Object of key/value pairs to associate with documentopts.secure
Boolean= If the document is sensitive, setting
secure
to true
will prevent it from being sent to OpenCalais for entity extractionopts.force_ocr
Boolean= Forces a document to OCR'd even if it has textopts.published_url
String= URL of page where document will be embeddedcallback
Function Callback that handles the API response