lazada-open-platform-sdk

Lazada Open Platform SDK for Node.js

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
lazada-open-platform-sdk
18102.0.0-04 years ago4 years agoMinified + gzip package size for lazada-open-platform-sdk in KB

Readme

Nodejs wrapper for Lazada Open Platform API
Build Status
| ! WIP project
Usage
  1. Install sdk
```shell
[~/project/dir] $ npm install lazada-open-platform-sdk
```
  1. Require LazadaAPI class
```js
import LazadaAPI from 'lazada-open-platform-sdk'
// OR
const LazadaAPI = require('lazada-open-platform-sdk')
```
  1. Instantiate a LazadaAPI Object
```js
/**
 * LazadaAPI class constructor
 * @param {string} appKey
 * @param {string} appSecret
 * @param {Venture} countryCode @ref: 'src/LazadaClient/constants.js'
 * countryCode should be one of the following
 * | 'SINGAPORE'
 * | 'THAILAND'
 * | 'MALAYSIA'
 * | 'VIETNAM'
 * | 'PHILIPPINES'
 * | 'INDONESIA'
 * @param {string?} accessToken require for some API
 */
const aLazadaAPI = new LazadaAPI(appKey, appSecret, 'SINGAPORE')
// OR
const accessToken = 'some_access_token'
const aLazadaAPIWithToken = new LazadaAPI(appKey, appSecret, 'SINGAPORE', accessToken)
```
1. Call API action with proper parameters
```js
// all API action return promise
aLazadaAPI
  .generateAccessToken({ code: 'auth_code' })
  .then(response => {
    const { access_token } = response // JSON data from Lazada's API
  })
// for API action that require authorization, you must set the accessToken first
aLazadaAPI.accessToken = 'some_access_token'
aLazadaAPI
  .getShipmentProviders()
  .then(response => {
    // JSON data from Lazada's API
  })
```
1. For available API actions, check the support table. For proper API request parameters, check Lazada's offcial documentation and source code located in src/LazadaClient/<namespace>
API Support
| Order | status | | ------------------------------ | ------------------ | | getDocument | :heavycheckmark: | | getFailureReasons | :heavycheckmark: | | getMultipleOrderItems | :heavycheckmark: | | getOrder | :heavycheckmark: | | getOrderItems | :heavycheckmark: | | getOrders | :heavycheckmark: | | setInvoiceNumber | :heavycheckmark: | | setStatusToCanceled | :heavycheckmark: | | setStatusToPackedByMarketplace | :heavycheckmark: | | setStatusToReadyToShip | :heavycheckmark: |
| Product | status | | --------------------- | ------------------ | | createProduct | :heavycheckmark: | | getBrands | :heavycheckmark: | | getCategoryAttributes | :heavycheckmark: | | getCategoryTree | :heavycheckmark: | | getProducts | :heavycheckmark: | | getQcStatus | :noentrysign: | | getResponse | :noentrysign: | | migrateImage | :heavycheckmark: | | migrateImages | :noentrysign: | | removeProduct | :heavycheckmark: | | setImages | :heavycheckmark: | | updatePriceQuantity | :heavycheckmark: | | updateProduct | :heavycheckmark: | | uploadImage | :noentrysign: |
| Finance | status | | --------------------- | --------------- | | getPayoutStatus | :noentrysign: | | getTransactionDetails | :noentrysign: |
| Logistics | status | | -------------------- | ------------------ | | getShipmentProviders | :heavycheckmark: |
| Seller | status | | ------------ | --------------- | | getSeller | :noentrysign: | | updateSeller | :noentrysign: | | updateUser | :noentrysign: |
| System | status | | ------------------- | ------------------ | | generateAccessToken | :heavycheckmark: | | refreshAccessToken | :heavycheckmark: |
| DataMoat | status | | ------------------- | --------------- | | dataMoatBatchLog | :noentrysign: | | dataMoatComputeRisk | :noentrysign: | | dataMoatLogin | :noentrysign: | | dataMoatOrder | :noentrysign: |
Development

Tools

  • node - runtime
  • babel - js transpiler
  • flow - type checker
  • jest - test runner
  • eslint - linter
  • vscode - recommended text editor

Convention

  1. sdk variables: camelCase
    api variables: snake_case or PascalCase

File structure

src/
├── LazadaAPI           // LazadaAPI: top level controller class
│   └── index.js        
├── LazadaClient        // LazadaClient: namespace seperated API actions
│   ├── index.js
│   ├── logistics.js
│   ├── order.js
│   ├── product.js
│   └── system.js
├── LazadaRequest       // LazadaRequest: responsible for network request
│   ├── index.js
│   └── signature       // logic for signing API request
│       └── index.js
├── __tests__           // all tests located here
└── index.js            // a.k.a. main.c
Design
const APIRequest = {
  appKey:      ":require",
  appSecret:   ":require",
  baseURL:     ":require" // Protocol (default: https) + Gateway (location specific)
  HttpAction:  "GET OR POST",  // API specific
  apiPath:     "action/path",  // API specific
  accessToken: ":optional",    // API specific
  payload: {}   // API specific
};
Reference

Lazada API Doc

https://open.lazada.com/doc/api.htm