UNPKG

shipstation-node

Version:
179 lines (178 loc) 6.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Batches = void 0; const BaseResource_1 = require("../../BaseResource"); /** * [Official Documentation](https://docs.shipstation.com/openapi/batches) * * Process labels in bulk and receive a large number of labels and customs forms in bulk responses. Batching is ideal * for workflows that need to process hundreds or thousands of labels quickly. */ class Batches extends BaseResource_1.BaseResource { constructor(shipstation) { super(shipstation, 'batches'); } /** * [Official Documentation](https://docs.shipstation.com/openapi/batches/list_batches) * * List the batches associated with your ShipStation account. * * @param options Options for the list request * * @returns A list of batches */ async list(options) { return this.shipstation.request({ url: this.baseUrl, method: 'GET', params: options }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/batches/create_batch) * * Create a batch containing multiple labels. * * @param options Options for the create request * * @returns The newly created batch */ async create(options) { return this.shipstation.request({ url: this.baseUrl, method: 'POST', data: options }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/batches/get_batch_by_id) * * Get batch details for a specific batch id. * * @param batchId The batch ID of the batch to retrieve [1-25] characters `^se(-[a-z0-9]+)+$` * @example "se-28529731" * * @returns A batch specified by its batch ID */ async getById(batchId) { return this.shipstation.request({ url: `${this.baseUrl}/${batchId}`, method: 'GET' }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/batches/get_batch_by_external_id) * * Retreive a batch using an external batch ID * * @param externalBatchId The external batch ID of the batch to retrieve * * @returns A batch specified by its external batch ID */ async getByExternalId(externalBatchId) { return this.shipstation.request({ url: `${this.baseUrl}/external_batch_id/${externalBatchId}`, method: 'GET' }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/batches/delete_batch) * * Delete a batch based on its batch id. Sets its status to 'archived'. * * @param batchId The batch ID of the batch to retrieve [1-25] characters `^se(-[a-z0-9]+)+$` * @example "se-28529731" */ async delete(batchId) { await this.shipstation.request({ url: `${this.baseUrl}/${batchId}`, method: 'DELETE' }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/batches/update_batch) * * Update a batch by id setting its status to 'archived'. * * @param batchId The batch ID of the batch to retrieve [1-25] characters `^se(-[a-z0-9]+)+$` * @example "se-28529731" */ async updateToArchived(batchId) { await this.shipstation.request({ url: `${this.baseUrl}/${batchId}`, method: 'PUT' }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/batches/add_to_batch) * * Add a shipment or rate to a batch. * * @param batchId The batch ID of the batch to retrieve [1-25] characters `^se(-[a-z0-9]+)+$` * @example "se-28529731" * * @param data The data to add to the batch */ async addToBatch(batchId, data) { await this.shipstation.request({ url: `${this.baseUrl}/${batchId}/add`, method: 'POST', data }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/batches/list_batch_errors) * * Errors in batches must be handled differently from synchronous requests. You must retrieve the status of your batch * by getting a batch and getting an overview of the statuses or by listing the batch errors. * * @param batchId The batch ID of the batch to retrieve [1-25] characters `^se(-[a-z0-9]+)+$` * @example "se-28529731" * * @param options Options for the list request * * @returns A list of batch errors */ async getErrors(batchId, options) { return this.shipstation.request({ url: `${this.baseUrl}/${batchId}/errors`, method: 'GET', params: options }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/batches/process_batch) * * Create and purchase the labels for the shipments included in the batch. * * @param batchId The batch ID of the batch to retrieve [1-25] characters `^se(-[a-z0-9]+)+$` * @example "se-28529731" * * @param options Options for the process request */ async processLabels(batchId, options) { await this.shipstation.request({ url: `${this.baseUrl}/${batchId}/process/labels`, method: 'POST', data: options }); } /** * [Official Documentation](https://docs.shipstation.com/openapi/batches/remove_from_batch) * * Remove specific shipment ids or rate ids from a batch. * * @param batchId The batch ID of the batch to retrieve [1-25] characters `^se(-[a-z0-9]+)+$` * @example "se-28529731" * * @param data The data to remove from the batch */ async removeFromBatch(batchId, data) { await this.shipstation.request({ url: `${this.baseUrl}/${batchId}/remove`, method: 'POST', data }); } } exports.Batches = Batches;