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

@kronsi/dhl

v2.1.7

Published

A library for using the DHL Express API

Downloads

48

Readme

DHL Lib

library to track, rate, ship or pickup something via DHL Express

Install

npm i @kronsi/dhl

Example Usage


var fs = require('fs');
var format = require("xml-formatter");
var dhlLib = require("./index.js");

const auth = {
    username: 'your username',
    password: 'your pw',
    accountNumber: 000000000,
}

const debug = true;
var dhl = new dhlLib(auth, debug);


//rate request
const reqRate = {
    ClientDetail: {
    },
    RequestedShipment: {
        DropOffType: 'REQUEST_COURIER',
        Ship: {
            Shipper: {
                StreetLines: 'Sender Address Line',
                City: 'Sender Address City',
                PostalCode: 'Sender Address ZipCode',
                CountryCode: 'Sender Address Country',
            },
            Recipient: {
                StreetLines: 'Recipient Address Line',
                City: 'Recipient Address City',
                PostalCode: 'Recipient Address ZipCode',
                CountryCode: 'Recipient Address Country',
            },
        },
        Packages: {
            RequestedPackages: {
                attributes: {
                    number: 1,
                },
                Weight: {
                    Value: 1,
                },
                Dimensions: {
                    Length: 12,
                    Width: 12,
                    Height: 12,
                },
            },
        },
        ShipTimestamp: getIsoDateTimeGmt(),
        UnitOfMeasurement: 'SI',
        Content: 'NON_DOCUMENTS',
        DeclaredValue: 100,
        DeclaredValueCurrecyCode: 'EUR',        
        Account: auth.accountNumber,
    },
};

dhl.rateRequest(reqRate).then((resRate) => {
    console.log(JSON.stringify(resRate, null, 4));
    fs.writeFileSync('rateRequest.response.xml', resRate.responseXml);
    fs.writeFileSync('rateRequest.request.xml', format(resRate.requestXml));

})


//shipment request
const reqShipment = {
    RequestedShipment: {
        ShipmentInfo: {
            DropOffType: 'REQUEST_COURIER',
            ServiceType: 'I',
            Account: auth.accountNumber,
            Currency: 'EUR',
            UnitOfMeasurement: 'SI',
            PackagesCount: 1,
            LabelType: 'PDF',
            LabelTemplate: 'ECOM26_84_001',
        },
        ShipTimestamp: getIsoDateTimeGmt(),
        PickupLocationCloseTime: '23:59',
        SpecialPickupInstruction: 'fragile items',
        //PickupLocation: 'west wing 3rd Floor',
        PaymentInfo: 'DAP',
        InternationalDetail: {
            Commodities: {
                NumberOfPieces: 1,
                Description: 'ppps sd',
                CountryOfManufacture: 'DE',
                Quantity: 1,
                UnitPrice: 10,
                CustomsValue: 1,
            },            
            Content: 'DOCUMENTS',
        },
        Ship: {
            Shipper: {
                Contact: {
                    PersonName: 'Sender Name',
                    CompanyName: 'Sender Company',
                    PhoneNumber: 'Sender Phone',
                    EmailAddress: 'Sender Email',
                },
                Address: {
                    StreetLines: 'Sender Address Line',
                    City: 'Sender Address City',
                    PostalCode: 'Sender Address ZipCode',
                    CountryCode: 'Sender Address Country',
                },
            },
            Recipient: {
                Contact: {
                    PersonName: 'Recipient Name',
                    CompanyName: 'Recipient Company',
                    PhoneNumber: 'Recipient Phone',
                    EmailAddress: 'Recipient Email',
                },
                Address: {
                    StreetLines: 'Recipient Address Line',
                    City: 'Recipient Address City',
                    PostalCode: 'Recipient Address ZipCode',
                    CountryCode: 'Recipient Address Country',
                },
            },
        },
        Packages: {
            RequestedPackages: {
                attributes: {
                    number: 1
                },
                InsuredValue: 10,
                Weight: 1,
                Dimensions: {
                    Length: 12,
                    Width: 12,
                    Height: 12,
                },
                CustomerReferences: 'TEST',
            },
        },
    },
};

dhl.shipmentRequest(reqShipment).then((resShipment) => {
    console.log(JSON.stringify(resShipment.response, null, 4));
    fs.writeFileSync('shipmentRequest.request.xml', format(resShipment.requestXml));
    fs.writeFileSync('shipmentRequest.response.xml', resShipment.responseXml);
    try {
    const graphicImage = Buffer.from(resShipment.response.LabelImage.GraphicImage, 'base64');
    fs.writeFileSync('shipmentRequest.response.pdf', graphicImage);
    }
    catch(e){
        console.log(e);
    }
})


//pickup
const reqPickup = {
    PickUpShipment: {
        ShipmentInfo: {
            ServiceType: 'U',
            Billing: {
                ShipperAccountNumber: auth.accountNumber,
                ShippingPaymentType: 'S',
            },
            UnitOfMeasurement: 'SI',
        },
        PickupTimestamp: getIsoDateTimeGmt(),
        InternationalDetail: {
            Commodities: {
                Description: 'Computer Parts',
            },
        },
        Ship: {
            Shipper: {
                Contact: {
                    PersonName: 'Sender Name',
                    CompanyName: 'Sender Company',
                    PhoneNumber: 'Sender Phone',
                    EmailAddress: 'Sender Email',
                    MobilePhoneNumber: 'Sender Mobile',
                },
                Address: {
                    StreetLines: 'Sender Address Line',
                    City: 'Sender Address City',
                    PostalCode: 'Sender Address ZipCode',
                    CountryCode: 'Sender Address Country',
                },
            },
            Recipient: {
                Contact: {
                    PersonName: 'Recipient Name',
                    CompanyName: 'Recipient Company',
                    PhoneNumber: 'Recipient Phone',                    
                },
                Address: {
                    StreetLines: 'Recipient Address Line',
                    City: 'Recipient Address City',
                    PostalCode: 'Recipient Address ZipCode',
                    CountryCode: 'Recipient Address Country',
                },
            },
        },
        Packages: {
            RequestedPackages: {
                attributes: {
                    number: 1,
                },
                Weight: 1.0,
                Dimensions: {
                    Length: 12,
                    Width: 12,
                    Height: 12,
                },
                CustomerReferences: 'My-PU-Call-1',
            },
        },
    },
};


dhl.requestPickup(reqPickup).then((resPickup) => {
    console.log(JSON.stringify(resPickup.response, null, 4));
    fs.writeFileSync('requestPickup.request.xml', format(resPickup.requestXml));
    fs.writeFileSync('requestPickup.response.xml', resPickup.responseXml);

});

Credits

Originally forked from mondalaci.