linet-sdk
v0.4.0
Published
Linet.org.il SDK for their API
Downloads
2
Readme
Linet SDK
Linet SDK for accessing Linet's API more conveniently.
Installation
npm install linet-sdk
Note!
This module has been tested and developed with node version 14. If you are experiencing any weird behavior in your project, try to test it with node version 14+.**
Configuration
- Create a Linet account.
- Go to your profile page. You can access it by clicking on the profile icon on the top corner and click on the "Update User" button, or access it from the User Management page. Then click on the "API Keys" tab and create a new API key. Don't forget to write down the hash key, as it will not be shown again.
Tip: Ideally, a better approach is to create a dedicated API user, and create a key under this user. This way, you can limit access and see who created the documents. - It is recommended to create an
.env
file, write your secret stuff there and load it in your code using dotenv or any preferred env loader. E.g.:LINET_LOGIN_ID=... LINET_LOGIN_HASH=... LINET_LOGIN_COMPANY=1
Usage
import { Linet } from 'linet-sdk';
const linet = new Linet(LINET_LOGIN_ID, LINET_LOGIN_HASH, LINET_LOGIN_COMPANY);
try {
const result = await linet.getItemById(1);
console.log(result);
} catch (e) {
console.error(e);
}
There is fourth argument to the constructor called fetchFunction
.
This is in case you want to change the dispatcher function to some other fetch-like function.
For example:
const linet = new Linet(LINET_LOGIN_ID, LINET_LOGIN_HASH, LINET_LOGIN_COMPANY, );
Note
If you are experiencing issues with import
while running your test code. Try to run the with node flag --experimental-specifier-resolution=node
.
node --experimental-specifier-resolution=node test.js
Documentation
Currently supported methods:
createDocument
( documentType: number, customerName: string [, options: object = {}] )
Create a document of any type.
createAccount
( accountType: number, name: string, options: object = {} )
Create an account of any type.
createItem
( sku: string, name: string, options: object = {} )
Create a new item.
getItemBySKU
( sku: string )
Retrieve an item using only SKU identifier.
getItemById
( itemId: number )
Retrieve an item using its internal ID.
getAccountByEmail
( email: string, filter: object = {} )
Retrieve an account using only email address. In case of multiple accounts with the same email, the first found one will be fetched. You can use the filter argument, to filter by other parameters.
searchAccounts
( filter: object )
Search accounts using the provided filter.
searchItems
( filter: object )
Search items using the provided filter.