dhl-ecommerce-solutions
Advanced tools
Comparing version 0.0.1 to 0.1.0
81
index.js
@@ -7,3 +7,3 @@ const cache = require('memory-cache'); | ||
const options = Object.assign({ | ||
environmentUrl: 'https://api-sandbox.dhlecs.com' | ||
environment_url: 'https://api-sandbox.dhlecs.com' | ||
}, args); | ||
@@ -36,3 +36,3 @@ | ||
json: _request, | ||
url: `${options.environmentUrl}/shipping/v4/label?format=${_options.format}` | ||
url: `${options.environment_url}/shipping/v4/label?format=${_options.format}` | ||
}; | ||
@@ -58,2 +58,73 @@ | ||
/** | ||
* Manifest specific open packages (recommended): Only packages specified in the request are added to a request id and only those items will be manifested. | ||
* Manifest all open items: The last 20,000 labels generated for the given pickup location are added to a request id and will be manifested. | ||
*/ | ||
this.createManifest = function(_request, callback) { | ||
this.getAccessToken(function(err, accessToken) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
const req = { | ||
auth: { | ||
bearer: accessToken.access_token | ||
}, | ||
json: _request, | ||
url: `${options.environment_url}/shipping/v4/manifest` | ||
}; | ||
request.post(req, function(err, res, response) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (res.statusCode !== 200) { | ||
const err = createError(res.statusCode); | ||
err.response = response; | ||
return callback(err); | ||
} | ||
callback(null, response); | ||
}); | ||
}); | ||
}; | ||
/** | ||
* The Dowload Manifest API is used to retrieve and download the manifests that were created using the Create Manifest API. | ||
* @param {string} pickup DHL eCommerce pickup account number. You will receive this after doing the onboarding with DHL sales | ||
* @param {string} requestId DHL eCommerce manifest request ID that was provided in the POST manifest response object | ||
*/ | ||
this.downloadManifest = function(pickup, requestId, callback) { | ||
this.getAccessToken(function(err, accessToken) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
const req = { | ||
auth: { | ||
bearer: accessToken.access_token | ||
}, | ||
json: true, | ||
url: `${options.environment_url}/shipping/v4/manifest/${pickup}/${requestId}` | ||
}; | ||
request.get(req, function(err, res, response) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (res.statusCode !== 200) { | ||
const err = createError(res.statusCode); | ||
err.response = response; | ||
return callback(err); | ||
} | ||
callback(null, response); | ||
}); | ||
}); | ||
}; | ||
/** | ||
* DHL eCommerce Americas Product Finder API enables clients to determine which DHL shipping products are suitable for a given shipping request including associated rates and estimated delivery dates. | ||
@@ -72,3 +143,3 @@ */ | ||
json: _request, | ||
url: `${options.environmentUrl}/shipping/v4/products` | ||
url: `${options.environment_url}/shipping/v4/products` | ||
}; | ||
@@ -97,3 +168,3 @@ | ||
this.getAccessToken = function(callback) { | ||
const url = `${options.environmentUrl}/auth/v4/accesstoken`; | ||
const url = `${options.environment_url}/auth/v4/accesstoken`; | ||
const key = `${url}?client_id=${options.client_id}`; | ||
@@ -154,3 +225,3 @@ | ||
json: true, | ||
url: `${options.environmentUrl}/tracking/v4/package?packageId=${packageId}` | ||
url: `${options.environment_url}/tracking/v4/package?packageId=${packageId}` | ||
}; | ||
@@ -157,0 +228,0 @@ |
@@ -30,3 +30,3 @@ { | ||
}, | ||
"version": "0.0.1" | ||
"version": "0.1.0" | ||
} |
@@ -18,3 +18,3 @@ # dhl-ecommerce-solutions | ||
client_secret: 'your_api_secret', | ||
environmentUrl: 'https://api-sandbox.dhlecs.com' | ||
environment_url: 'https://api-sandbox.dhlecs.com' | ||
}); | ||
@@ -21,0 +21,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23948
197