documentcloud v0.1.0
node-documentcloud
A Node.js wrapper around the DocumentCloud API. Requires Node.js >= 4.
Installation
npm install --save documentcloudUsage
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 DocumentClient('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,
// ...API Docs
DocumentCloudClient
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
usernameString= DocumentCloud username (optional, defaultnull)passwordString= DocumentCloud password (optional, defaultnull)apiUrlString= An override for the DocumentCloud API base URL. (optional, defaulthttps://www.documentcloud.org/api/)
Examples
var DocumentCloudClient = require('documentcloud');
var client = new DocumentCloudClient('email@example.com', 'example_pw');ProjectClient
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
clientObject Instance of DocumentCloudClient
create
Creates a project.
Parameters
titleString Title of project.optsObject= Additional parameters to be included with project creationcallbackFunction Callback to handle API response
delete
Deletes a project. Documents associated with the project are not effected.
Parameters
list
Lists all projects associated with the account.
Parameters
callbackFunction Callback to handle API response
update
Updates 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_idNumber The project identifieroptsObject Parameters to be set during the updatecallbackFunction Callback to handle API response
DocumentClient
Handles 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
clientObject Instance of DocumentCloudClient
delete
Deletes a document on DocumentCloud.
Parameters
entities
Returns a list of entities associated with a document.
Parameters
get
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,
// ...search
Searches the DocumentCloud service for documents.
Parameters
qString The search queryoptsObject= Additional search parametersopts.pageNumber= Response page number (defaults to 1)opts.per_pageNumber= The number of documents to return per page (defaults to 10, max is 1,000)opts.sectionsBoolean= Include document sectionsopts.annotationsBoolean= Include document annotationsopts.dataBoolean= Include key/value data in resultsopts.mentionsNumber= Include highlighted mentions of search phrase (none by default, max is 10)opts.orderString= Order documents are listed (defaults tocreated_at, choices are:score,created_at,title,page_count,source)
callbackFunction Callback that handles the API response
update
Update 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_idString Document identifieroptsObject Values to updateopts.titleString= Title of documentopts.sourceString= Source of documentopts.descriptionString= Description of documentopts.related_articleString= URL of article associated with documentopts.published_urlString= URL of page where document will be embeddedopts.accessString= Sets access level (defaults toprivate, choices are:private,public,organization) (optional, defaultprivate)opts.dataObject= Object of key/value pairs to associate with document
callbackFunction Callback that handles the API response
upload
Uploads 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 URLtitleString Title of uploaded documentoptsObject= Additional parameters to be included with uploadopts.sourceString= Source of documentopts.descriptionString= Description of documentopts.languageString= Language of document, will be used determine which OCR package to be used (optional, defaulteng)opts.related_articleString= URL of article associated with documentopts.accessString= Sets access level (defaults toprivate, choices are:private,public,organization) (optional, defaultprivate)opts.projectNumber= Numeric ID of project to add document toopts.dataObject= Object of key/value pairs to associate with documentopts.secureBoolean= If the document is sensitive, settingsecuretotruewill prevent it from being sent to OpenCalais for entity extractionopts.force_ocrBoolean= Forces a document to OCR'd even if it has textopts.published_urlString= URL of page where document will be embedded
callbackFunction Callback that handles the API response
Major Thanks
- Thanks to DocumentCloud for creating and maintaining such an awesome service.
- Thanks to python-documentcloud, who served as inspiration for many parts of this.
10 years ago