shipmentCreated()
This method is called when a shipment is created for one or more items in one or more sales orders. A single shipment may contain items from multiple sales orders, and a single sales order may be fulfilled by multiple shipments.
Syntax
module.exports = async function shipmentCreated(transaction, shipment) { // Your code here}
import { Transaction, SalesOrderShipment } from "@shipengine/connect";export default async function shipmentCreated( transaction: Transaction, shipment: SalesOrderShipment): Promise<void> { // Your code here}
Parameters
transaction
A transaction object containing information about the transaction and session state.
shipment
The shipment that was created.
Name | Type | Nullable? | Description |
---|---|---|---|
trackingNumber | string | The master tracking number for the entire shipment. For single-piece shipments, this will be the same as the package tracking number. For multi-piece shipments, this may be a separate tracking number, or the same tracking number as one of the packages. This string will not contain newline characters. | |
identifiers | Your own identifiers for this shipment. | ||
salesOrder | object | The sales order associated with this shipment. | |
salesOrder.id | The marketplace's unique ID for the sales order. This string must not contain newline characters. | ||
salesOrder.identifiers | Your own identifiers for this sales order. | ||
shipTo | The recipient's contact info and address. | ||
shipDateTime | The date/time that the shipment was shipped or is expected to ship. This is not guaranteed to be in the future. | ||
contents | object[] | The items inside the package. | |
contents[].quantity | object | The quantity of this item in the sales order. | |
contents[].quantity.value | number | The quantity of items in this sales order item. The minimum value for this property is | |
contents[].currency | string | ✔ | The three character ISO 4217 code of the currency used for all monetary amounts. |
contents[].notes | object[] | ✔ | Additional notes associated with this notification or its sales order. |
contents[].notes[].type | ✔ | The type for this note. | |
contents[].notes[].text | string | ✔ | The note text itself. |
contents[].salesOrderItem | object | ✔ | The sales order associated with this item. This property may be null. If it is provided, all its required properties, listed below, will be included. |
contents[]
.salesOrderItem
.id | string | The marketplace's unique ID for the sales order item. This string must not contain newline characters. | |
contents[]
.salesOrderItem
.sku | string | The Stock Keeping Unit. This string must not contain newline characters. | |
contents[]
.salesOrderItem
.identifiers | Your own identifiers for this sales order item. | ||
contents[].product | object | ✔ | The product associated with this item. This property may be null. If it is provided, all its required properties, listed below, will be included. |
contents[].product.id | string | The product catalog's unique ID for the order. This string must not contain newline characters. | |
contents[].product.sku | string | The Stock Keeping Unit. This string must not contain newline characters. | |
contents[].product.upc | string | The Universal Product Code for this item. This string must not contain newline characters. | |
contents[].product.isbn | string | The International Standard Book Number for this item. This string must not contain newline characters. | |
contents[].product.asin | string | The Amazon Standard Identification Number for this item. This string must not contain newline characters. | |
contents[]
.product
.fulfillmentSku | string | The Stock Keeping Unit related to the fulfillment of this item. This string must not contain newline characters. | |
contents[]
.product
.inventoryID | string | The inventory ID for this item. This string must not contain newline characters. | |
contents[]
.product
.identifiers | Your own identifiers for this product. | ||
contents[]
.product
.details | A list of details associated with this product. | ||
trackingURL | ✔ | The URL of a webpage where the customer can track the shipment. | |
carrierCode | string | ✔ | If the shipment is being fulfilled using a well-known third-party carrier, such as UPS, FedEx, DHL, etc., then this field specifies the carrier. |
carrierServiceCode | string | ✔ | If the shipment is being fulfilled using a well-known third-party carrier, such as UPS, FedEx, DHL, etc., then this field specifies the service code. |
fulfillmentService | ✔ | If the shipment is being fulfilled using a well-known third-party carrier, such as UPS, FedEx, DHL, etc., then this field specifies the carrier service. | |
shipFrom | ✔ | The sender's contact info and address. | |
notifyBuyer | boolean | ✔ | Instructs the order source on whether to notify the buyer. Omit, or set to null, to retain the order source's default behavior. |
fulfillmentCost | ✔ | The amount it costs to fulfill this shipment. | |
insuranceCost | ✔ | The amount of insurance purchased for this shipment. |
Return Value
void
This method is used to notify your application when a shipment is created. It does not return a value.
Example
async function shipmentCreated(transaction, shipment) { // STEP 1: Validation // Add any desired validation here // STEP 2: Create the data that the order source's API expects const data = { operation: "create_shipment", session_id: transaction.session.id, shipment_id: shipment.trackingNumber }; // STEP 3: Call the order source's API await apiClient.request({ data });}
export default async function shipmentCreated( transaction: Transaction<Session>, shipment: SalesOrderShipment,): Promise<void> { // STEP 1: Validation // Add any desired validation here // STEP 2: Create the data that the order source's API expects const data = { operation: "create_shipment", session_id: transaction.session.id, shipment_id: shipment.trackingNumber }; // STEP 3: Call the order source's API await apiClient.request({ data });}