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

51tracking

v0.1.3

Published

node.js SDK for 51Tracking API

Downloads

11

Readme

51tracking-sdk-nodejs

node.js SDK for 51Tracking API

Contact: [email protected]

Official document

Document

Index

  1. Installation
  2. Testing
  3. SDK
    1. Couriers

    2. Trackings

    3. Air Waybill

Installation

npm install 51tracking

Quick Start

const Tracking51 = require('51tracking')
const key = 'you api key'
const tracking51 = new Tracking51(key)
tracking51.couriers.getAllCouriers()
    .then(result => console.log(result))
    .catch(e => console.log(e))

Testing

npm run test or npm test

Error handling

对于异步操作,可以使用 Promise 的 catch 方法进行监听异常

tracking51.couriers.getAllCouriers()
    .then(result => console.log(result))
    .catch(e => console.error('An error occurred:', e.message))

Couriers

返回所有支持的快递公司列表

https://api.51Tracking.com/v4/couriers/all

tracking51.couriers.getAllCouriers()
    .then(result => console.log(result))
    .catch(e => console.log(e))

Trackings

单个物流单号实时添加且查询

https://api.51Tracking.com/v4/trackings/create

const params = {
    'tracking_number': '9400111899562537624326',
    'courier_code': 'usps',
    'order_number': '',
    'customer_name': '',
    'title': '',
    'language': 'en',
    'note': 'test Order'
}
tracking51.trackings.createTracking(params)
    .then(result => console.log(result))
    .catch(e => console.log(e))
获取多个物流单号的查询结果

https://api.51Tracking.com/v4/trackings/get

const params = {
    'tracking_numbers': '9400111899562539126562,9400111899562537624656',
    'courier_code': 'usps',
    'created_date_min': '2023-08-23T06:00:00+00:00',
    'created_date_max': '2023-09-05T07:20:42+00:00',
}
tracking51.trackings.getTrackingResults(params)
    .then(result => console.log(result))
    .catch(e => console.log(e))
添加多个物流单号(一次调用最多创建 40 个物流单号)

https://api.51Tracking.com/v4/trackings/batch

const params = [{
    'tracking_number': '9400111899562537680047',
    'courier_code':'usps'
},{
    'tracking_number': '9400111899562537680048',
    'courier_code':'usps'
}]
tracking51.trackings.batchCreateTrackings(params)
.then(result => console.log(result))
.catch(e => console.log(e))
根据ID更新物流信息

https://api.51Tracking.com/v4/trackings/update/{id}

const params = {
    'customer_name': 'New name',
    'note':'New test order note'
}
const idString = "9a135b15b5d983e1d8950d99022db0c7"
tracking51.trackings.updateTrackingByID(idString, params)
.then(result => console.log(result))
.catch(e => console.log(e))
通过ID删除单号

https://api.51Tracking.com/v4/trackings/delete/{id}

const idString = "9a135b15b5d983e1d8950d99022db0c7"
tracking51.trackings.deleteTrackingByID(idString)
.then(result => console.log(result))
.catch(e => console.log(e))
通过ID重新查询过期的单号

https://api.51Tracking.com/v4/trackings/retrack/{id}

const idString = "99f4ed7fc73aa83fe68fd69ab6458b28"
tracking51.trackings.retrackTrackingByID(idString)
.then(result => console.log(result))
.catch(e => console.log(e))

Air Waybill

查询航空运单的结果

https://api.51Tracking.com/v4/awb

const params = {
    'awb_number': '235-69030430',
}
tracking51.airWaybills.createAnAirWayBill(params)
.then(result => console.log(result))
.catch(e => console.log(e))

响应状态码

51Tracking 使用传统的HTTP状态码来表明 API 请求的状态。通常,2xx形式的状态码表示请求成功,4XX形式的状态码表请求发生错误(比如:必要参数缺失),5xx格式的状态码表示 51tracking 的服务器可能发生了问题。

Http CODE|META CODE|TYPE | MESSAGE ----|-----|--------------|------------------------------- 200 |200 | 成功 | 请求响应成功。 400 |400 | 错误请求 | 请求类型错误。请查看 API 文档以了解此 API 的请求类型。 400 |4101 | 错误请求 | 物流单号已存在。 400 |4102 | 错误请求 | 物流单号不存在。请先使用「Create接口」将单号添加至系统。 400 |4103 | 错误请求 | 您已超出 API 调用的创建数量。每次创建的最大数量为 40 个快递单号。 400 |4110 | 错误请求 | 物流单号(tracking_number) 不符合规则。 400 |4111 | 错误请求 | 物流单号(tracking_number)为必填字段。 400 |4112 | 错误请求 | 查询ID无效。 400 |4113 | 错误请求 | 不允许重新查询。您只能重新查询过期的物流单号。 400 |4120 | 错误请求 | 物流商简码(courier_code)的值无效。 400 |4121 | 错误请求 | 无法识别物流商。 400 |4122 | 错误请求 | 特殊物流商字段缺失或填写不符合规范。 400 |4130 | 错误请求 | 请求参数的格式无效。 400 |4160 | 错误请求 | 空运单号(awb_number)是必需的或有效的格式。 400 |4161 | 错误请求 | 此空运航空不支持查询。 400 |4165 | 错误请求 | 查询失败:未创建空运单号。 400 |4166 | 错误请求 | 删除未创建的空运单号失败。 400 |4167 | 错误请求 | 空运单号已存在,无需再次创建。 400 |4190 | 错误请求 | 当前查询额度不足。 401 |401 | 未经授权 | 身份验证失败或没有权限。请检查并确保您的 API 密钥正确无误。 403 |403 | 禁止 | 禁止访问。请求被拒绝或不允许访问。 404 |404 | 未找到 | 页面不存在。请检查并确保您的链接正确无误。 429 |429 | 太多请求| 超出 API 请求限制,请稍后重试。请查看 API 文档以了解此 API 的限制。 500 |511 | 服务器错误 | 服务器错误。请联系我们: [email protected]。 500 |512 | 服务器错误 | 服务器错误。请联系我们:[email protected]。 500 |513 | 服务器错误 | 服务器错误。请联系我们: [email protected]