Node implementation for the Harvest rest API v2 using async/await.
More info on the Harvest Rest API
Table of Contents
Installation
$ npm install node-harvest-api
Initializing
Create a Personal Access Token in Harvest here.
const Harvest = const account_id = 12345const token = 'Your Access Token'const app_name = 'Your Application Name' const harvest = account_id token app_name
Usage
All methods (see below) are asynchronous and return a promise. You can relove the promise yourself or use 'await'.
let invoices_promise = harvestinvoicesall invoices_promise
let invoices = await harvestinvoicesall for let invoice in invoices console
All arguments are supported. Please see the API docs for more info on this.
Resources
All resources described in the API docs are available using getters.
Almost every resource has the following methods:
-
all()
Will fetch all records. Same as get() without arguments. -
get(args)
Fetches records by query arguments. Check out the API docs for the correct arguments.
Check out how to use pagination. -
raw(args)
Same as get() but returns the entire response object instead of only the relevant records. This will only return the first page of a request. Subsequent pages (if any) are to be retrieved using the 'next' or 'next_page' properties of the response. -
find(id)
Retrieves one record by id. -
create(args)
Creates a new record. -
udpate(id, args)
Updates a record by id. -
delete(id)
Removes a record.
See below for examples.
Company
The company resource is a special case. It is a method on its own.
let settings = await harvest
Users
let user_id = 123 harvestusersallharvestusersharvestusersharvestusersharvestusersharvestusers
Special method to retrieve the currently authenticated user:
harvestusers
User Project Assignments
let user_id = 123 harvestusersproject_assignmentsallharvestusersproject_assignments
Pass 'me' to the pipe()
method to get all project assignments for the currently authenticated user:
harvestusersproject_assignmentsall
Clients
let client_id = 123 harvestclientsallharvestclientsharvestclientsharvestclientsharvestclientsharvestclients
Contacts
let contact_id = 123 harvestcontactsallharvestcontactsharvestcontactsharvestcontactsharvestcontactsharvestcontacts
Invoices
let invoice_id = 1234 harvestinvoicesallharvestinvoicesharvestinvoicesharvestinvoicesharvestinvoicesharvestinvoices
Some shortcuts are available to change the status of an invoice:
let invoice_id = 1234 harvestinvoicesharvestinvoicesharvestinvoicesharvestinvoices
Invoices Messages
let invoice_id = 1234 harvestinvoicesmessagesallharvestinvoicesmessagesharvestinvoicesmessagesharvestinvoicesmessages
Invoices Payments
let invoice_id = 1234 harvestinvoicespaymentsallharvestinvoicespaymentsharvestinvoicespaymentsharvestinvoicespayments
Invoice Item Categories
let invoice_item_category_id = 1234 harvestinvoice_item_categoriesallharvestinvoice_item_categoriesharvestinvoice_item_categoriesharvestinvoice_item_categoriesharvestinvoice_item_categoriesharvestinvoice_item_categories
Estimates
let estimate_id = 1234 harvestestimatesallharvestestimatesharvestestimatesharvestestimatesharvestestimatesharvestestimates
Some shortcuts are available to change the status of an estimate:
let estimate_id = 1234 harvestestimatesacceptestimate_idharvestestimatesharvestestimatesharvestestimates
Estimate Messages
let estimate_id = 1234 harvestestimatesmessagesallharvestestimatesmessagesharvestestimatesmessagesharvestestimatesmessages
Estimate Item Categories
let estimate_item_category_id = 1234 harvestestimate_item_categoriesallharvestestimate_item_categoriesharvestestimate_item_categoriesharvestestimate_item_categoriesharvestestimate_item_categoriesharvestestimate_item_categories
Expenses
let expense_id = 123 harvestexpensesallharvestexpensesharvestexpensesharvestexpensesharvestexpensesharvestexpenses
Expense Categories
let expense_category_id = 1234 harvestexpense_categoriesallharvestexpense_categoriesharvestexpense_categoriesharvestexpense_categoriesharvestexpense_categoriesharvestexpense_categories
Tasks
let task_id = 1234 harvesttasksallharvesttasksharvesttasksharvesttasksharvesttasksharvesttasks
Time Entries
let time_entry_id = 1234 harvesttime_entriesallharvesttime_entriesharvesttime_entriesharvesttime_entriesharvesttime_entriesharvesttime_entries
Extra methods to start and stop timers:
harvesttime_entriesharvesttime_entries
Projects
let project_id = 1234 harvestprojectsallharvestprojectsharvestprojectsharvestprojectsharvestprojectsharvestprojects
Project User Assignments
let project_id = 123 harvestprojectsuser_assignmentsallharvestprojectsuser_assignmentsharvestprojectsuser_assignmentsharvestprojectsuser_assignmentsharvestprojectsuser_assignmentsharvestprojectsuser_assignments
Project Task Assignments
let project_id = 123 harvestprojectstask_assignmentsallharvestprojectstask_assignmentsharvestprojectstask_assignmentsharvestprojectstask_assignmentsharvestprojectstask_assignmentsharvestprojectstask_assignments
Pagination
You can get a limited set of records when using the get()
method by passing both the 'page' and 'per_page' parameters.
let tasks = await harvesttasks
The max amount of records per page is 100 as set by the Harvest API.
There's a little helper you can use to shorten this:
let tasks = await harvesttasks
The 'limit' functionality makes it possible to get more than 100 items.
let tasks = await harvesttasks
Full Example
const Harvest = const account_id = 12345const token = 'Your Access Token'const app_name = 'Your Application Name' const harvest = account_id token app_name { let active_users = await harvestusers for let user of active_users console }