Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

neto-api

matt-downs78MIT2.1.3TypeScript support: included

A promise based client for the Neto Ecommerce API.

neto, ecommerce, api

readme

neto-api

npm npm

A promise based client for the Neto Ecommerce API.

npm i neto-api

Initialisation

Before you start making calls, you will need to initialise the API like so:

const { NetoAPI } = require("neto-api");

const mySite = new NetoAPI({
  url: "https://myawesomesite.neto.com.au",
  key: "api-key",
  user: "user" // optional
});

This library can also be used with Neto's OAuth program by providing the oauth_clientId and oauth_secret configuration options instead of key. Here is an example:

const mySite = new NetoAPI({
  url: "https://myawesomesite.neto.com.au",
  oauth_clientId: "clientId",
  oauth_secret: "secret"
});

Authentication

This library doesn't handle any authentication logic, it assumes that you already have obtained an API key or OAuth secret by some other means. More information on how to retrieve credentials can be found by visiting Neto's API documentation

Basic syntax

Once the library is initialised, you can use it like so:

mySite.type // See below for a list of supported types
  .method() // See below for a list of methods for each type (generally add, get or update)
  .exec() // Returns a promise that resolves with the API response in JSON format
  .then(response) // Response object is returned via callback
  .catch(err); // Always handle your errors ;)

Supported types and methods

Examples

item.add

mySite.item
  .add({ SKU: "smp_3" })
  .exec()
  .then(response => {
    console.log(response);
  })
  .catch(err => console.log(err));

order.get

mySite.order
  .get({ OrderStatus: ["New", "Pick"] })
  .output(["OrderID"])
  .exec()
  .then(response => {
    for (let order of response.Order) {
      console.log(order);
    }
  })
  .catch(err => console.log(err));

customer.update

mySite.customer
  .update({ Username: "someguy", EmailAddress: "bob@email.com" })
  .exec()
  .then(response => {
    console.log(response);
  })
  .catch(err => console.log(err));

Advanced usage

Chaining

.add() and .update() methods can be chained together with themselves to improve readability - the request itself will only be sent when .exec() is called. Check it out below:

mySite.item
  .add({ SKU: "smp_1" })
  .add({ SKU: "smp_2" })
  .add({ SKU: "smp_3" })
  .exec()
  .then(response => {
    console.log(response);
  })
  .catch(err => console.log(err));

This allows you to some other cool stuff, such as building a bulk request to execute at some time in the future:

// Expose a copy of the request type
var addItems = api.item;
// Do some stuff...
addItems = addItems.add({ SKU: "smp_1" });
// Do some other stuff...
addItems = addItems.add({ SKU: "smp_2" });
// Keep building the request...
addItems = addItems.add({ SKU: "smp_3" });

// Finally execute the request at a later time
addItems
  .exec()
  .then(response => {
    console.log(response);
  })
  .catch(err => console.log(err));

Chaining .get() methods will be supported soon, I promise.

async/await support

Because this library is built on promises, it supports the use of async and await operators. Here's an example:

async function addItem() {
  try {
    var response = mySite.item.add({ SKU: "smp_1" }).exec();
    // Do some stuff...
    console.log(await response);
  } catch (err) {
    console.log(err);
  }
}
addItem();

It's that easy!

Supported types and methods

.cart

Method Neto API Action
.get( CartFilter ) GetCart

.category

Method Neto API Action
.add( Category | Category[] ) AddCategory
.get( CategoryFilter ) GetCategory
.update( Category | Category[] ) UpdateCategory

.content

Method Neto API Action
.add( Content | Content[] ) AddContent
.get( ContentFilter ) GetContent
.update( Content | Content[] ) UpdateContent

.currency

Method Neto API Action
.getSettings() GetCurrencySettings
.updateSettings( CurrencySettings ) UpdateCurrencySettings

.customer

Method Neto API Action
.add( Customer | Customer[] ) AddCustomer
.get( CustomerFilter ) GetCustomer
.update( Customer | Customer[] ) UpdateCustomer
.addLog( CustomerLog | CustomerLog[] ) AddCustomerLog
.updateLog( CustomerLog | CustomerLog[] ) UpdateCustomerLog

.item

Method Neto API Action
.add( Item | Item[] ) AddItem
.get( ItemFilter ) GetItem
.update( Item | Item[] ) UpdateItem

.order

Method Neto API Action
.add( Order | Order[] ) AddOrder
.get( OrderFilter ) GetOrder
.update( Order | Order[] ) UpdateOrder

.payment

Method Neto API Action
.add( Payment | Payment[] ) AddPayment
.get( PaymentFilter ) GetPayment
.getMethods() GetPaymentMethods

.rma

Method Neto API Action
.add( Rma | Rma[] ) AddRma
.get( RmaFilter ) GetRma

.shipping

Method Neto API Action
.getMethods() GetShippingMethods
.getQuote( ShippingQuote ) GetShippingQuote

.supplier

Method Neto API Action
.add( Supplier | Supplier[] ) AddSupplier
.get( SupplierFilter ) GetSupplier
.update( Supplier | Supplier[] ) UpdateSupplier

.voucher

Method Neto API Action
.add( Voucher | Voucher[] ) AddVoucher
.get( VoucherFilter ) GetVoucher
.update( Voucher | Voucher[] ) UpdateVoucher

.warehouse

Method Neto API Action
.add( Warehouse | Warehouse[] ) AddWarehouse
.get( WarehouseFilter ) GetWarehouse
.update( Warehouse | Warehouse[] ) UpdateWarehouse

Endpoint actions not supported yet

  • <input disabled="" type="checkbox"> Accounting
    • <input disabled="" type="checkbox"> UpdateAccountingSystemRelatedAccount
    • <input disabled="" type="checkbox"> DeleteAccountingSystemRelatedAccount
    • <input disabled="" type="checkbox"> AddAccountingSystemRelatedAccount
    • <input disabled="" type="checkbox"> GetAccountingSystemRelatedAccounts

Neto API documentation available here.

Note: This is currently a personal project of mine and is not offically endorsed or supported by Neto.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[2.1.1] - 2019-09-03

Security

  • Updated dependencies

[2.1.0] - 2019-06-11

Added

  • Add support for oauth headers

Security

  • Updated dependencies

[2.0.4] - 2018-10-30

Changed

  • Updated .npmignore

Security

  • Updated dependencies

[2.0.3] - 2018-05-22

Changed

  • Updated .npmignore
  • Updated code to use spread operator where possible
  • Updated code to use es6 imports

Security

  • Updated dependencies

[2.0.2] - 2018-05-05

Changed

  • Updated readme

[2.0.1] - 2018-05-05

Changed

  • Updated npm description and keywords

[2.0.0] - 2018-02-17

Changed

  • Module import syntax

[1.2.2] - 2018-02-17

Fixed

  • Fixed incorrect API action on warehouse.get() function

Changed

  • Updated TypeScript and @types packages
  • Updated tests for 100% coverage of /modules

[1.2.1] - 2018-01-31

Fixed

  • TS warning property then does not exist on .exec()

[1.2.0] - 2018-01-22

Changed

  • Entire project is now compiled from TypeScript source files. Supported editors should now show rich snippets and code completion when using the library.

Added

  • More unit tests

[1.1.1] - 2018-01-02

Changed

  • user key is no longer required when initialising the library
  • Updated mocha devDependency to latest version

Fixed

  • Fixed documentation table layout on npmjs.com

[1.1.0] - 2017-12-21

Added

  • Ability to use .get() without .output()
  • More tests for type .item
  • Debug param to all .exec() methods

Changed

  • Filter request body is now built in the GetModule parent class each time .get() or .output() is called
  • API request for all .get() methods with filters has been moved into the GetModule parent class and referenced with super
  • Licence changed to MIT

[1.0.1] - 2017-12-13

Added

  • Another chaining example to README.md

Changed

  • Package description
  • Lots of changes to README.md to improve readability

[1.0.0] - 2017-12-13

  • Lift off!