Prerequisites:
- NodeJs
- NPM
- Typescript
To install the dependencies and build the SDK run make build
To test the SDK locally:
- Run
make test
- Now you should be able to import the SDK to your Nodejs files in
/testing
directory (ex.const delivery_sdk = require('@lalamove/lalamove-js');
)
To format code and show the styling problems run make format
You can specify the environment in a config object SDKClient.Config
. By default it will initialize client for sandbox
env. To use it for production just pass production
string.
const SDKClient = require("@lalamove/lalamove-js");
const sdkClient = new SDKClient.ClientModule(
new SDKClient.Config(
"public_key",
"secret_key",
"sandbox"
)
);
sdkClient.Quotation
To create new quotation for your order call
sdkClient.Quotation.create(market: string, quotationPayload: QuotationPayload): Promise<IQuotation>;
function.
You can import SDKClient.QuotationPayloadBuilder
, a helper function that will allow you to build the payload needed for Quotation in easy manner.
const co = {
lat: "22.3353139",
lng: "114.1758402",
};
const co2 = {
lat: "22.3203648",
lng: "114.169773",
};
const stop1 = {
coordinates: co,
address: "Wu Kai Sha Road",
};
const stop2 = {
coordinates: co2,
address: "Wu Kai Sha Road",
};
const quotationPayload = SDKClient.QuotationPayloadBuilder.quotationPayload()
.withLanguage("en_HK")
.withServiceType("COURIER")
.withStops([stop1, stop2])
.build();
await sdkClient.Quotation.create("HK", quotationPayload);
Promise of
IQuotation {
id: string;
scheduleAt: Date;
serviceType: string;
specialRequests: string[];
expiresAt: Date;
priceBreakdown: PriceBreakdown;
isRouteOptimized: boolean;
stops: Stop[];
}
const quotDetail = await sdKClient.Quotation.retrieve(market: string, quotationId: string);
Promise of
IQuotation {
id: string;
scheduleAt: Date;
serviceType: string;
specialRequests: string[];
expiresAt: Date;
priceBreakdown: PriceBreakdown;
isRouteOptimized: boolean;
stops: Stop[];
}
SDKCLient.Order
To place an new order
sdKClient.Order.create(market: string, orderPayload: OrderPayload): Promise<IOrder>;
function.
You can import SDKClient.OrderPayloadBuilder
, a helper function that will allow you to build the payload needed for Order in easy manner.
const orderPayload = SDKClient.OrderPayloadBuilder.orderPayload()
.withIsPODEnabled(true)
.withQuotationID(quotation.id)
.withSender({
stopId: quotation.stops[0].stopId,
name: "Michal",
phone: "+85256847123",
})
.withRecipients([
{
stopId: quotation.stops[1].stopId,
name: "Rustam",
phone: "+85256847456",
},
])
.withMetadata({
"internalId": "xyx211d"
})
.build();
const order = await sdKClient.Order.create("HK", orderPayload);
Promise of
interface IOrder {
id: string;
quotationId: string;
priceBreakdown: PriceBreakdown;
driverId: string;
shareLink: string;
status: string;
distance: Measurement;
stops: StopWithContact[];
metadata: object;
}
To edit an existing order
sdKClient.Order.edit(market: string, orderId: string, patchOrderPayload: PatchOrderPayload): Promise<IOrder>;
function.
You can import SDKClient.PatchOrderPayloadBuilder
, a helper function that will allow you to build the payload needed for Order in easy manner.
const patchOrderPayload = SDKClient.PatchOrderPayloadBuilder.patchOrderPayload()
.withStops([
{
coordinates: {
lat: "22.3353139",
lng: "114.1758402",
},
address: "Wu Kai Sha Road",
name: "Michal",
phone: "+85256847123",
},
{
coordinates: {
lat: "22.2827206",
lng: "114.2123009",
},
address: "Quarry Bay, Hong Kong",
},
{
coordinates: {
lat: "22.3203648",
lng: "114.169773",
},
address: "Wu Kai Sha Road",
name: "Rustam",
phone: "+85256847456",
},
])
.build();
const order = await sdKClient.Order.edit("HK", order.id, payload);
Promise of
interface IOrder {
id: string;
quotationId: string;
priceBreakdown: PriceBreakdown;
driverId: string;
shareLink: string;
status: string;
distance: Measurement;
stops: StopWithContact[];
metadata: object;
}
await sdKClient.Order.retrieve("HK", order.id);
Promise of
interface IOrder {
id: string;
quotationId: string;
priceBreakdown: PriceBreakdown;
driverId: string;
shareLink: string;
status: string;
distance: Measurement;
stops: StopWithContact[];
metadata: object;
}
await sdKClient.Order.addPriorityFee("HK", order.id, "15")
Promise of
interface IOrder {
id: string;
quotationId: string;
priceBreakdown: PriceBreakdown;
driverId: string;
shareLink: string;
status: string;
distance: Measurement;
stops: StopWithContact[];
metadata: object;
}
await sdKClient.Order.cancel("HK", order.id);
Promise of
interface IOrder {
id: string;
quotationId: string;
priceBreakdown: PriceBreakdown;
driverId: string;
shareLink: string;
status: string;
distance: Measurement;
stops: StopWithContact[];
metadata: object;
}
sdkClient.Driver
To retrieve driver details for your order call
sdkClient.Driver.retrieve(market, driverId, orderID)
function.
You can get driverId
from order details when a driver picks up the order. The resulting object that will be returned by the function above is as follows:
{
"driverId": "93965",
"name": "Driver's Name'",
"phone": "+85210002001",
"plateNumber": "**T-00*",
"photo": "www.example.com/photo"
}
To change the driver for your order call
sdkClient.Driver.cancel(market, driverId, orderID)
function.
You can get driverId
from order details when a driver picks up the order. The return value of the function above is as follows:
true
A market is the location where Lalamove has launched its services. This SDK allows you to get all the service types in all cities in the specified market
To retrieve all cities with their corresponding service types in a specific market call
sdkClient.Market.retrieve(market)
sdkClient.City
To retrieve service types for a specific city
sdkClient.City.retrieve(market, id)
The id
param is a city identifier. You can see different city codes by calling retrieve.Market