pitney-bowes
Advanced tools
Comparing version 0.0.2 to 0.1.0
42
index.js
@@ -13,2 +13,44 @@ const cache = require('memory-cache'); | ||
this.createShipment = function(shipment, _options, callback) { | ||
this.getOAuthToken(function(err, oAuthToken) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
const req = { | ||
auth: { | ||
bearer: oAuthToken.access_token | ||
}, | ||
headers: {}, | ||
json: shipment, | ||
method: 'POST', | ||
url: `${options.baseUrl}/v1/shipments` | ||
}; | ||
if (_options.integratorCarrierId) { | ||
req.headers['X-PB-Integrator-CarrierId'] = _options.integratorCarrierId; | ||
} | ||
if (_options.shipmentGroupId) { | ||
req.headers['X-PB-ShipmentGroupId'] = _options.shipmentGroupId; | ||
} | ||
if (_options.transactionId) { | ||
req.headers['X-PB-TransactionId'] = _options.transactionId; | ||
} | ||
request(req, function(err, res, body) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (res.statusCode !== 201) { | ||
return callback(createError(res.statusCode, body)); | ||
} | ||
callback(null, body); | ||
}); | ||
}); | ||
}; | ||
this.getOAuthToken = function(callback) { | ||
@@ -15,0 +57,0 @@ // Try to get the token from memory cache |
@@ -30,3 +30,3 @@ { | ||
}, | ||
"version": "0.0.2" | ||
"version": "0.1.0" | ||
} |
@@ -22,2 +22,77 @@ # pitney-bowes | ||
### pitneyBowes.createShipment(shipment, options, callback) | ||
This operation creates a shipment and purchases a shipment label. The API returns the label as either a Base64 string or a link to a PDF. | ||
**Example** | ||
```javascript | ||
const shipment = { | ||
documents: [ | ||
{ | ||
contentType: 'BASE64', | ||
fileFormat: 'ZPL2', | ||
printDialogOption: 'NO_PRINT_DIALOG', | ||
size: 'DOC_6X4', | ||
type: 'SHIPPING_LABEL' | ||
} | ||
], | ||
fromAddress: { | ||
addressLines: ['4750 Walnut Street'], | ||
cityTown: 'Boulder', | ||
countryCode: 'US', | ||
name: 'Pitney Bowes', | ||
postalCode: '80301', | ||
stateProvince: 'CO' | ||
}, | ||
parcel: { | ||
dimension: { | ||
height: 9, | ||
length: 12, | ||
unitOfMeasurement: 'IN', | ||
width: 0.25 | ||
}, | ||
weight: { | ||
unitOfMeasurement: 'OZ', | ||
weight: 3 | ||
} | ||
}, | ||
rates: [ | ||
{ | ||
carrier: 'PBPRESORT', | ||
parcelType: 'LGENV', | ||
serviceId: 'BPM' | ||
} | ||
], | ||
shipmentOptions: [ | ||
{ | ||
name: 'PERMIT_NUMBER', | ||
value: '1234' | ||
}, | ||
{ | ||
name: 'SHIPPER_ID', | ||
value: '9015544760' | ||
} | ||
], | ||
toAddress: { | ||
addressLines: ['114 Whitney Ave'], | ||
cityTown: 'New Haven', | ||
countryCode: 'US', | ||
name: 'John Doe', | ||
postalCode: '06510', | ||
stateProvince: 'CT' | ||
} | ||
}; | ||
const options = { | ||
integratorCarrierId: '987654321', | ||
shipmentGroupId: '500002', | ||
transactionId: crypto.randomBytes(12).toString('hex') | ||
}; | ||
pitneyBowes.createShipment(shipment, options, function(err, shipment) { | ||
console.log(shipment); | ||
}); | ||
``` | ||
### pitneyBowes.getOAuthToken(callback) | ||
@@ -24,0 +99,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
22438
160
157