UNPKG

@stylusapparel/shipstation-api-node

Version:
538 lines (432 loc) 14.9 kB
# stylusapparel/shipstation-api-node A NodeJS wrapper for connecting to ShipStation system using the auth credentials provided from ShipStation. You can also view the full documentation of Stylus APIs [here](https://www.shipstation.com/docs/api/) ## Install ```bash $ npm install @stylusapparel/shipstation-api-node ``` OR ```bash $ yarn add @stylusapparel/shipstation-api-node ``` ## Usage After having installed it, simply require it and create an instance of wrapper using your own shipstation `apiKey` and `apiSecret`, and start calling methods! ```javascript const shipStationWrapper = require("@stylusapparel/node-shipstation"); const shipStationWrapperClient = shipStationWrapper.createClient( "YOUR_SHIPSTATION_API_KEY", "YOUR_SHIPSTATION_API_SECRET", { // additional http options timeout: 3000, // optional, request timeout in milliseconds } ); ``` # Orders ## Get Order This method can be used to retrieve a single order by `orderId`. ```js shipStationWrapperClient.orders .get(orderId) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the get order request/response payload [here](https://www.shipstation.com/docs/api/orders/get-order/) ## Get All Orders Obtains a list of orders that match the specified criteria. All of the available filters are optional. ```js shipStationWrapperClient.orders .getAll({ // filter object customerName: "stylus", itemKeyword: "leggings", sortBy: "OrderDate", pageSize: 100, }) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the get all orders request/response payload [here](https://www.shipstation.com/docs/api/orders/list-orders/) ## Create Order Create a new order or update an existing order. If the `orderKey` is specified, ShipStation will attempt to locate the order with the specified `orderKey`. If found, the existing order with that key will be updated. If the `orderKey` is not found, a new order will be created with that `orderKey`. ```js shipStationWrapperClient.orders.create({ "orderNumber": "TEST-ORDER-API-DOCS", "orderKey": "0f6bec18-3e89-4881-83aa-f392d84f4c74", "orderDate": "2015-06-29T08:46:27.0000000", "paymentDate": "2015-06-29T08:46:27.0000000", "shipByDate": "2015-07-05T00:00:00.0000000", ... ... ... }) .then((response) => { console.log("success",response); // true }) .catch((error) => { console.log("error",error.status,error); }); ``` You can see create order request/response payload [here](https://www.shipstation.com/docs/api/orders/create-update-order/) **Note:-**  This method does not support partial updates, the entire resource must be provided. For partial update, use `.update()` function. ## Create Orders Create or Update multiple orders in one request. If the `orderKey` is specified, ShipStation will attempt to locate the order with the specified `orderKey`. If found, the existing order with that key will be updated. If the `orderKey` is not found, a new order will be created with that `orderKey`. ```js shipStationWrapperClient.orders.bulkCreate([{ "orderNumber": "TEST-ORDER-API-DOCS", "orderKey": "0f6bec18-3e89-4881-83aa-f392d84f4c74", "orderDate": "2015-06-29T08:46:27.0000000", "paymentDate": "2015-06-29T08:46:27.0000000", "shipByDate": "2015-07-05T00:00:00.0000000", ... ... ... }]) .then((response) => { console.log("success",response); // true }) .catch((error) => { console.log("error",error.status,error); }); ``` You can see the bulk order create request/response payload [here](https://www.shipstation.com/docs/api/orders/create-update-multiple-orders/) **Note:-**  This method does not support partial updates, the entire resource must be provided. ## Update Order This method can be used to partially update an order by providing `orderId` and update payload. ```js shipStationWrapperClient.orders.update(orderId, { "paymentDate": "2015-07-02T06:46:29.0000000", "shipByDate": "2015-08-04T02:11:10.0000000", ... ... ... }) .then((response) => { console.log("success",response); }) .catch((error) => { console.log("error",error.status,error); }); ``` You can see the order update request/response payload [here](https://www.shipstation.com/docs/api/orders/create-update-order/) ## Delete Order Removes an order from ShipStation's UI. Note this is a "soft" delete action so the order will still exist in the shipstation database as inactive. ```js shipStationWrapperClient.orders .delete(orderId) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the delete order request/response payload [here](https://www.shipstation.com/docs/api/orders/delete/) ## Cancel Order Cancel an order by marking orderStatus as `cancelled`. ```js shipStationWrapperClient.orders .cancel(orderId) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` Response payload for cancel order is same as order update function response ## Create Order Label Creates a shipping label for a given order. The labelData field returned in the response is a base64 encoded PDF value. Simply decode and save the output as a PDF file to retrieve a printable label. ```js shipStationWrapperClient.orders .label(orderId, { carrierCode: "fedex", serviceCode: "fedex_2day", packageCode: "package", confirmation: null, shipDate: "2014-04-03", ... ... ... }) .then((response) => { console.log("success",response); }) .catch((error) => { console.log("error",error.status,error); }); ``` You can see the order label request/response payload [here](https://www.shipstation.com/docs/api/orders/create-label/) ## Mark an Order as Shipped Marks an order as shipped without creating a label in ShipStation. ```js shipStationWrapperClient.orders .markShipped(orderId, { orderId: 93348442, carrierCode: "usps", shipDate: "2014-04-01", trackingNumber: "913492493294329421", notifyCustomer: true, notifySalesChannel: true, }) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the delete order request/response payload [here](https://www.shipstation.com/docs/api/orders/mark-as-shipped/) ## Hold Order Until This method will change the status of the given order to On Hold until the date specified, when the status will automatically change to Awaiting Shipment. ```js shipStationWrapperClient.orders .hold(orderId, holdUntilDate) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the delete order request/response payload [here](https://www.shipstation.com/docs/api/orders/hold-order-until/) # Shipments ## Create Shipment Label Creates a shipping label. The `labelData` field returned in the response is a base64 encoded PDF value. Simply decode and save the output as a PDF file to retrieve a printable label. ```js shipStationWrapperClient.shipments .createLabel({ carrierCode: "fedex", serviceCode: "fedex_ground", packageCode: "package", ... ... ... }) .then((response) => { console.log("success",response); }) .catch((error) => { console.log("error",error.status,error); }); ``` You can see the shipment label request/response payload [here](https://www.shipstation.com/docs/api/shipments/create-label/) ## Get Rates Retrieves shipping rates for the specified shipping details. ```js shipStationWrapperClient.shipments .getRates({ carrierCode: "fedex", serviceCode: null, packageCode: null, ... ... ... }) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the shipment rates request/response payload [here](https://www.shipstation.com/docs/api/shipments/get-rates/) ## Get All Shipments Obtains a list of shipments that match the specified criteria. ```js shipStationWrapperClient.shipments .getAll({ recipientName: "stylus", recipientCountryCode: "US", pageSize: 15, ... ... ... }) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the shipment list request/response payload [here](https://www.shipstation.com/docs/api/shipments/list/) ## Void Shipment Label Voids the specified label by shipmentId. ```js shipStationWrapperClient.shipments .voidLabel(shipmentId) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the shipment label void request/response payload [here](https://www.shipstation.com/docs/api/shipments/void-label/) # Carriers ## Get Carrier By Code Retrieves the shipping carrier account details for the specified carrierCode. Use this method to determine a carrier's account balance. ```js shipStationWrapperClient.carriers .get(carrierCode) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the carrier info request/response payload [here](https://www.shipstation.com/docs/api/carriers/get/) ## Get All Carriers List all shipping providers connected to this account. ```js shipStationWrapperClient.carriers .getAll() .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the carriers list request/response payload [here](https://www.shipstation.com/docs/api/carriers/list/) ## Get All Services Retrieves the list of available shipping services provided by the specified carrier ```js shipStationWrapperClient.carriers .getAllServices(carrierCode) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the carriers list request/response payload [here](https://www.shipstation.com/docs/api/carriers/list-services/) ## Get All Packages Retrieves a list of packages for the specified carrier. ```js shipStationWrapperClient.carriers .getAllPackages(carrierCode) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the carriers list request/response payload [here](https://www.shipstation.com/docs/api/carriers/list-packages/) # WareHouses ## Create Warehouse Adds a Ship From Location (formerly known as warehouse) to your account. ```js shipStationWrapperClient.warehouses .create({ warehouseName: "New Ship From Location", originAddress: { name: "NM Warehouse", company: "White Sands Co.", street1: "4704 Arabela Dr.", street2: null, street3: null, city: "Las Cruces", state: "NM", postalCode: "80012", country: "US", phone: "512-111-2222", residential: true, }, returnAddress: null, isDefault: false, }) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the carrier info request/response payload [here](https://www.shipstation.com/docs/api/warehouses/create/) ## Get Warehouse Returns a list of active Ship From Locations (formerly known as warehouses) on the ShipStation account. ```js shipStationWrapperClient.warehouses .get(warehouseId) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the carrier info request/response payload [here](https://www.shipstation.com/docs/api/warehouses/get/) ## Get All Warehouse Retrieves a list of your Ship From Locations (formerly known as warehouses). ```js shipStationWrapperClient.warehouses .getAll() .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the carrier info request/response payload [here](https://www.shipstation.com/docs/api/warehouses/list/) ## Update Warehouse Updates an existing Ship From Location (formerly known as warehouse). This call does not currently support partial updates. The entire resource must be provided in the body of the request. If a "returnAddress" object is not specified, your "originAddress" will be used as your "returnAddress". ```js shipStationWrapperClient.warehouses .update({ warehouseId: 12345, warehouseName: "API Ship From Location", originAddress: { name: "API Warehouse", company: "ShipStation", street1: "2815 Exposition Blvd", street2: null, street3: null, ... ... ... }, returnAddress: { name: "API Ship From Location", company: "ShipStation", ... ... ... }, createDate: "2015-07-02T08:38:31.4870000", isDefault: true, }) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the carrier info request/response payload [here](https://www.shipstation.com/docs/api/warehouses/update/) ## Delete Warehouse Removes a warehouse from ShipStation's UI. ```js shipStationWrapperClient.warehouses .delete(warehouseId) .then((response) => { console.log("success", response); }) .catch((error) => { console.log("error", error.status, error); }); ``` You can see the carrier info request/response payload [here](https://www.shipstation.com/docs/api/warehouses/delete/)