Topship Open Server Docs
This library allows you to quickly and easily use the Topship Africa Shipping API via Node.js.
Installation
The following recommended installation requires npm. If you are unfamiliar with npm, see the npm docs. Npm comes installed with Node.js since node version 0.8.x, therefore, you likely already have it.
Obtain an API Key
Grab your API Key from the Topship Africa.
Setup Environment Variables
Do not hardcode your Topship Africa into your code. Instead, use an environment variable or some other secure means of protecting your Topship API Key. Following is an example of using an environment variable.
Install Package
$ npm install topship-africa
You may also use yarn to install
$ yarn add topship-africa
The following is the minimum needed code to get Qoutes and Prices for Shipment. Use this example, and modify the to and from variables:
const { quotesAndPrices } = require("topship-africa");
quotesAndPrices(
{
shipmentDetail: {
{
senderDetails: {
cityName: "Yaba",
countryCode: "NG"
},
receiverDetails: {
cityName: "Washington",
countryCode: "US"
},
totalWeight: 4
}
}
}
);
The following is the minimum needed code to get Pickup Rate for Shipment. Use this example, and modify the to and from variables:
const { pickupRate } = require("topship-africa");
pickupRate({
input: {
senderDetail: {
addressLine1: "268, Herbert Macauly way",
addressLine2: "",
country: "Nigeria",
countryCode: "NG",
state: "Lagos",
city: "Yaba",
},
pickupDate: "2024-02-15T09:14:29.000Z",
},
});
The following is the minimum needed code to get Booked Shipment. Use this example, and modify the to and from variables:
const { getBookedShipment } = require("topship-africa");
getBookedShipment({
filter: {
take: 10,
page: 2,
},
});
The following is the minimum needed code to get Single Shipment. Use this example, and modify the to and from variables:
const { getShipmentById } = require("topship-africa");
getShipmentById("5e9f8f9f8d8f8d8f8d8f8f8f");
The following is the minimum needed code to Cancel Single Shipment. Use this example, and modify the to and from variables:
const { cancelShipmentById } = require("topship-africa");
cancelShipmentById("5e9f8f9f8d8f8d8f8d8f8f8f");
The following is the minimum needed code to Track Shipment. Use this example, and modify the to and from variables:
const { trackShipment } = require("topship-africa");
trackShipment("T619979552");
The following is the minimum needed code to get State List. Use this example, and modify the to and from variables:
const { getStates } = require("topship-africa");
getStates("NG");
The following is the minimum needed code to get City List. Use this example, and modify the to and from variables:
const { getCities } = require("topship-africa");
getCities("NG");
The following is the minimum needed code to Book a Shipment. Use this example, and modify the to and from variables:
const { saveShipment } = require("topship-africa");
saveShipment(
{
shipment: [
{
items: [
{
category:
"Appliance || BeautyProducts || Jewelry || ComputerSupplies || HomeDecor || BabySupplies || TelevisionAndEntertainment || KitchenAccessories || Furniture || Gadgets || SolarPanelsAndInverter || VehicleParts || ClothingAndTextile || SportAccessories || GymEquipment || Fashion || Furniture || Education || Drones || Document || OriginalArtwork || ArtPrints || FoodItems || Medication || Fish || Herbs || BatteryLiquidElectrical || Crayfish || Driedfish || Prawns || Otherfish || GoatMeat || CowSkin || Beef || Snail || OtherMeats || PaintingsAndDrawings || ArtifactsAndHistoricalMonuments || LaptopsAndTablets || Phones || HeadphonesOrEarphonesOrAirPods || Wristwatches || VideoGames || OtherElectronicsOrGadgets || GoldSilverAndFineJewelry || PreciousStonesAndJewels || CostumeJewelry || HerbsAndPlants || FoodstuffAndFoodProducts || Drinks || Others",
description: "Gucci Bag",
weight: 4,
quantity: 1,
value: 99,
},
],
itemCollectionMode: "DropOff || PickUp",
pricingTier: "Budget || Express || FedEx || Premium || LastMileBudget",
insuranceType: "None || Premium || Extended",
insuranceCharge: 0,
discount: 200,
shipmentRoute: "Import || Export || Domestic",
shipmentCharge: 128000,
pickupCharge: 4000,
deliveryLocation: "Lagos",
pickupId: "topship-1234",
pickupPartner: "Fez || Standard || Dellyman || Sendstack || Messenger",
valueAddedTaxCharge: 800,
senderDetail: {
name: "John Doe",
email: "john.doe@gmail.com",
phoneNumber: "08080808080",
addressLine1: "SPencer",
addressLine2: "Alagomeji",
addressLine3: "Yaba",
country: "Nigeria",
state: "Lagos",
city: "Lagos",
countryCode: "NG",
postalCode: "100001",
},
receiverDetail: {
name: "Jane Doe",
email: "jane.doe@gmail.",
phoneNumber: "070347890",
addressLine1: "Garki",
addressLine2: "Maitama",
addressLine3: "Suleja",
country: "Nigeria",
state: "Abuja",
city: "Abuja",
countryCode: "NG",
postalCode: "111000",
},
},
],
},
process.env.TOPSHIP_API_KEY
);
The following is the minimum needed code to Pay for Shipment. Use this example, and modify the to and from variables:
const { payForShipment } = require("topship-africa");
payForShipment(
{
detail: {
shipmentId: "string",
},
},
process.env.TOPSHIP_API_KEY
);