npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aramex-api-wrapper

v1.2.21

Published

A simple wrapper for Aramex SOAP API to manage shipments, tracking, and printing labels.

Downloads

1,923

Readme

Aramex API Wrapper

A lightweight Node.js wrapper for Aramex's SOAP API to manage shipments, tracking, and label printing for Zid platform order management.


Project github

Features

  • Easy configuration of Aramex client and shipper details.
  • Create shipments dynamically based on order data.
  • Track shipments by Airway Bill (AWB) numbers.
  • Generate and print shipment labels.

Installation

npm install aramex-api-wrapper



Setup
Configure Aramex
Before using the API, configure your Aramex clientInfo and shipperDetails. You only need to do this once during your application setup.

javascript
Copy code
import { configureAramex } from 'aramex-api-wrapper';

// Set up Aramex client and shipper details
configureAramex(
  {
    UserName: 'your_username',
    Password: 'your_password',
    Version: 'v1.0',
    AccountNumber: 'your_account_number',
    AccountPin: 'your_account_pin',
    AccountEntity: 'RUH', // Example: RUH for Riyadh
    AccountCountryCode: 'SA', // Example: SA for Saudi Arabia
  },
  {
    Reference1: 'Ref123',
    PartyAddress: {
      Line1: 'Shipper Address Line 1',
      City: 'Riyadh',
      CountryCode: 'SA',
    },
    Contact: {
      PersonName: 'Shipper Name',
      PhoneNumber1: '123456789',
      EmailAddress: '[email protected]',
    },
  }
);
Example Usage
1. Create Shipment
Use the createShipment function to generate a shipment based on an order object.

Input:
An order object should include the following properties:

id: Unique order ID.
order_total: Total order value.
shipping.address: Shipping address including street, city, and country.
customer: Customer details including name, mobile, and email.
currency.order_currency.code: Currency code (e.g., "AED").
products: Array of product names in the order.
Code Example:
javascript
Copy code
import { createShipment } from 'aramex-api-wrapper';

const order = {
  id: 12345,
  order_total: "100.00",
  shipping: {
    address: {
      street: "Customer Street",
      city: { name: "Dubai" },
      country: { name: "الإمارات العربية المتحدة" },
    },
  },
  customer: {
    name: "Customer Name",
    mobile: "971500000000",
    email: "[email protected]",
  },
  currency: { order_currency: { code: "AED" } },
  products: [{ name: "Product 1" }, { name: "Product 2" }],
};

(async () => {
  try {
    const shipmentResponse = await createShipment(order);
    console.log('Shipment Created:', shipmentResponse);
  } catch (error) {
    console.error('Error Creating Shipment:', error);
  }
})();
2. Track Shipments
Use the trackShipments function to track shipments by their Airway Bill (AWB) numbers.

Input:
An array of AWB numbers to track.

Code Example:
javascript
Copy code
import { trackShipments } from 'aramex-api-wrapper';

(async () => {
  try {
    const trackingResponse = await trackShipments(['AWB123456789', 'AWB987654321']);
    console.log('Tracking Info:', trackingResponse);
  } catch (error) {
    console.error('Error Tracking Shipments:', error);
  }
})();
3. Print Shipment Label
Use the printShipmentLabel function to generate a shipment label for a given Airway Bill (AWB) number.

Input:
A single AWB number.

Code Example:
javascript
Copy code
import { printShipmentLabel } from 'aramex-api-wrapper';

(async () => {
  try {
    const labelResponse = await printShipmentLabel('AWB123456789');
    console.log('Label Info:', labelResponse);
  } catch (error) {
    console.error('Error Printing Label:', error);
  }
})();
Full Example Workflow
Here’s a complete example demonstrating the entire workflow:

Configure Aramex client and shipper details.
Create a shipment.
Track the shipment.
Print the shipment label.
Full Code Example:
javascript
Copy code
import { configureAramex, createShipment, trackShipments, printShipmentLabel } from 'aramex-api-wrapper';

// Step 1: Configure Aramex
configureAramex(
  {
    UserName: 'your_username',
    Password: 'your_password',
    Version: 'v1.0',
    AccountNumber: 'your_account_number',
    AccountPin: 'your_account_pin',
    AccountEntity: 'RUH',
    AccountCountryCode: 'SA',
  },
  {
    Reference1: 'Ref123',
    PartyAddress: {
      Line1: 'Shipper Address Line 1',
      City: 'Riyadh',
      CountryCode: 'SA',
    },
    Contact: {
      PersonName: 'Shipper Name',
      PhoneNumber1: '123456789',
      EmailAddress: '[email protected]',
    },
  }
);

// Step 2: Create Shipment
const order = {
  id: 12345,
  order_total: "100.00",
  shipping: {
    address: {
      street: "Customer Street",
      city: { name: "Dubai" },
      country: { name: "الإمارات العربية المتحدة" },
    },
  },
  customer: {
    name: "Customer Name",
    mobile: "971500000000",
    email: "[email protected]",
  },
  currency: { order_currency: { code: "AED" } },
  products: [{ name: "Product 1" }, { name: "Product 2" }],
};

(async () => {
  try {
    // Create the shipment
    const shipmentResponse = await createShipment(order);
    console.log('Shipment Created:', shipmentResponse);

    const awbNumber = shipmentResponse.Shipments.Shipment.AWBNumber;

    // Step 3: Track the shipment
    const trackingResponse = await trackShipments([awbNumber]);
    console.log('Tracking Info:', trackingResponse);

    // Step 4: Print the shipment label
    const labelResponse = await printShipmentLabel(awbNumber);
    console.log('Label Info:', labelResponse);
  } catch (error) {
    console.error('Error:', error);
  }
})();
API Reference
1. configureAramex(clientInfo, shipperDetails)
Configures global Aramex client and shipper details.

Parameters:

clientInfo (Object): Aramex client credentials.
UserName, Password, Version, AccountNumber, AccountPin, AccountEntity, AccountCountryCode.
shipperDetails (Object): Shipper information.
Includes Reference1, PartyAddress, and Contact fields.
2. createShipment(order)
Creates a shipment for an order.

Parameters:

order (Object): Contains details about the order, customer, and shipping.
Returns:

A Promise resolving to the shipment creation response.
3. trackShipments(awbNumbers)
Tracks shipments by their Airway Bill (AWB) numbers.

Parameters:

awbNumbers (Array): List of AWB numbers.
Returns:

A Promise resolving to the tracking details.
4. printShipmentLabel(awbNumber)
Generates a shipment label for the given Airway Bill (AWB) number.

Parameters:

awbNumber (String): The AWB number for the shipment.
Returns:

A Promise resolving to the label information.
License
This project is licensed under the MIT License.

Contributing
Feel free to open issues or submit pull requests for bug fixes and new features. Contributions are welcome!