npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rantalainen/koho-api-helper

v7.0.2

Published

Koho Sales API helper library

Downloads

24

Readme

KohoApiHelper

API Helper for Koho Sales ERP (http://www.kohosales.com/)

Installation

Install from npm:

npm install @rantalainen/koho-api-helper

Usage

Import to NodeJS project

const KohoApiHelper = require('@rantalainen/koho-api-helper').KohoApiHelper;

Import to TypeScript project

import { KohoApiHelper } from '@rantalainen/koho-api-helper';

Setup with options

const kohoApiHelperOptions = {
  token: 'KOHO_API_TOKEN', // Token from Company Koho settings
  companyId: 1234, // Company ID in Koho, optional if enterpriseId is defined

  // Optional options
  enterpriseId: 1234, // Enterprise ID in Koho, if defined make sure to use enterprise token
  url: 'https://suite-beta.koho-online.com/api', // You can override API url with this property

  // If you are spamming multiple requests to Koho, you should set this to true so that connections are reused
  // This option was depcerated in 6.0.0, internal keepAliveAgent enabled by default
  // useKeepAliveAgent: true,

  // Added in 2.0.0, disable streaming for Koho GET requests, defaults to false and GET requests are streamed
  disableStreaming: true,

  // Added in 3.1.0, optional throttleOptions
  throttleOptions: {
    enabled: true, // default: true
    delay: 30000, // default: 15000
    maxRetries: 1 // default: 3
  },

  // Disable keepAliveAgent, which is true by default (one can also pass own instance of https.Agent)
  keepAliveAgent: false,

  // Disable dnsCache, which is true by default (using got's cacheable-lookup)
  dnsCache: false
};

const helper = new KohoApiHelper(kohoApiHelperOptions);

Implemented methods and resources

The following api resources have been implemented:

  • contracts Invoicing contracts
  • customers Customers
  • customersCategories Customer categories (asiakasryhmä)
  • customersGroups Customer groups (erikoisryhmä)
  • employees Employees
  • invoices Invoices
  • persons Customer contact persons
  • products Products (product types)
  • projects Projects
  • sales Sales (pikakauppa)
  • notifications Notifications
  • offers Offers
  • customReports Custom reports

Getter examples

Each resource type has getAll() and getById(1234) getters (below examples with contracts):

const contracts = await helper.contracts.getAll(); // array of contract instances
const contracts = await helper.contracts.getById(1234); // single contract instance

There are also some resource specific getters for customers:

const customers = await helper.customers.getByName('Customer Oy');
const customers = await helper.customers.getByNumber(1234);
const customers = await helper.customers.getByOrganizationId('1234567-8');

Above result can also be achieved by calling getAll() with parameters:

const customers = await helper.customers.getAll({ name: 'Customer Oy' });
const customers = await helper.customers.getAll({ number: 1234 });
const customers = await helper.customers.getAll({ organization_id: '1234567-8' });

Request query parameters can be passed freely. With call below you can find projects that have been updated after said date:

const projects = await helper.projects.getAll({ updated_after: '2020-06-01' });

Setter examples

Update by id:

await helper.projects.updateById(1234, { name: 'New project name' });

Or by fetching resource first and using update method:

const project = await helper.projects.getById(1234); // Get single project instance

await project.update({
  name: 'New project name'
});

:warning: Warning!

When updating custom_parameters you should always first fetch the resource and then make the update with existing custom_parameters as in example below. Otherwise you will write over existing custom_parameters.

const customer = await helper.customers.getById(1234);

await customer.update({
  custom_parameters: {
    ...customer.custom_parameters, // assign existing parameters

    updated_parameter: 'Updated' // update other parameters
  }
});

You can also use patch_parameters for updating custom_parameters.

await customer.update({
  patch_parameters: {
    updated_parameter: 'Updated'
  }
});

Create example

Create new customer

const customer = await helper.customers.create({
  name: 'Example Customer Oy',
  description: 'Customer generated by Koho Api Helper',
  organization_id: '1234567-8'
});

Changelog

  • 1.1.0 Add customersGroups and customersCategories resources
  • 1.2.0 Add notifications
  • 1.3.0 Add offers
  • 1.4.0 Add productsCatalogs + code refactoring
  • 1.5.0 Add customersFinancialStatements
  • 1.6.0 Add accountingTargets, employeeProfiles, employeeTeams
  • 1.7.0 Add workSessions, workSessionAssignments, workSessionAssignmentTemplates
  • 1.8.0 Add customReports
  • 1.9.0 Add workSessionShifts and workSessionShiftTypes, add new helper option useKeepAliveAgent
  • 1.10.0 Add support for updating notifications, companies methods, accounting assignments methods and better error messages
  • 2.0.0 Add streaming by default for GET requests to avoid throttling, can be disabled by disableStreaming option
  • 2.1.0 Add support for offer notifications (extends notifications methods)
  • 3.0.0 Update streaming and keepAliveAgent handling
  • 3.0.3 Add projectTemplates (experimental)
  • 3.1.0 Add throttle handling and throttleOptions to normal requests
  • 4.0.0 Implement timeout
  • 4.1.0 Add datafiles
  • 4.2.0 Add incidents
  • 4.2.1 Add requestText to custom-reports
  • 5.0.0 New HTTPS Keep Alive agent implementation and defaults with agentkeepalive package
  • 6.0.0 Enable dnsCache and keepAliveAgent by default, update dependencies and typings

Miscellaneous examples

Update employee groups.

await employee.update({
  group_ids: [1234, 123]
});