Code Monkey home page Code Monkey logo

zoho-ts's Introduction

npm version

Zoho TS

A typescript / node.js library used to work with Zoho Finance Suite APIs: Zoho Inventory, Zoho Books and Zoho Invoice. These APIs are for most entities the same, apart from some specific functions.
There are several functions already created, but in the end they are all custom. Some of them are documented and some are reverse-engineered and implemented in this library to have an optimised, easy way working with the Zoho APIs.

All entities are fully typed.

Installation

yarn add @trieb.work/zoho-ts
npm i @trieb.work/zoho-ts

Usage on server

Make sure to select the correct datacenter for your API client credentials: e.g. ".com" or ".eu". You can also select, which API endpoint to use - Zoho Books, Zoho Invoice or Zoho Inventory. Most API endpoints are the same and work the same. You just need to select the product, that you have licensed.

import { Zoho, ZohoApiClient } from "@trieb.work/zoho-ts";

const zoho = new Zoho(
    await ZohoApiClient.fromOAuth({
      orgId: "243546",
      dc: ".com",
      apiFlavour: "invoice",
      scope: "ZohoInvoice.fullaccess.all"
      client: {
        id: "",
        secret: "",
      },
    }),
  );

You can decide, which API to use - Zoho Inventory, Zoho Books, Zoho Invoice. Currently, you can only decide per instance. It is planned to make it possible to decide which API to use on function level.

Authentication

The library on the server should be used with a client ID and a client secret, that you can register at the developer console: https://api-console.zoho.eu/ (Self Client)

Usage in Browser Context (use cookies for auth)

import { Zoho, ZohoApiClient } from "@trieb.work/zoho-ts";

const zoho = new Zoho(
    await ZohoApiClient.fromCookies({ 
        orgId: "",
        cookie: "",
        zsrfToken: ""
    }),
  );

Implemented entities

Entity Functions
bankaccount list
contact create, get, delete, list, addAddress,updateAddress, listContactPersons
contactperson create, get, delete, list
invoice create, get, delete, list, createFromSalesOrder, sent
item create, get, delete, list, createGroup, deleteGroup, getComposite
organizations list
package create, get, delete, list,bulkCreateQuickShipment, createShipment, markDelivered, deleteShipmentOrder
payment create, get, delete, list
salesorder create, get, delete, list, update, confirm, markVoid, setCustomFieldValue, search
tax list
warehouse get, list

Usage example:

import { Zoho, ZohoApiClient } from "@trieb.work/zoho-ts";

const zoho = new Zoho(
    await ZohoApiClient.fromOAuth({
      orgId: "243546",
      dc: ".com",
      client: {
        id: "",
        secret: "",
      },
    }),
  );

/// Get all payments that were modified in the last hour
const payments = await zoho.payment.list({
    lastModifiedTime: subHours(new Date(), 1),
})  

Error Handling

The library includes a custom error type, that you can use to handle the from Zoho returned error type:

try {
  
  await zoho.invoice.createFromSalesOrder(id)

} catch(err) {
  if ((err as ZohoApiError).code === 36026) {
    console.warn(
      "Aborting sync of this invoice since it was already created. Original Error: " +
        err.message,
    );
  } else {
    console.error(err.message);
  }
}

zoho-ts's People

Contributors

jannikzed avatar chronark avatar streamsurfer avatar tilman avatar zmart-sen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.