createShipment
Creates a new shipment for a basket.
This method communicates with the createShipment endpoint of the Vue Storefront API Middleware. In turn, it receives data from the createShipmentForBasket or the Create shipment for a basket endpoints exposed by SCAPI / OCAPI depending on the middleware configuration.
The shipment is initialized with values provided in the body document and can be updated with further data API calls. Considered from the body are the following properties if specified: - the ID - the shipping address - the shipping method - gift boolean flag - gift message - custom properties
Signature
export declare function createShipment(
props: ShipmentCreateParams & {
basketId?: string;
}
): Promise<import("commerce-sdk/dist/checkout/checkout").ShopperBaskets.Basket>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
props | Required | ShipmentCreateParams & { basketId?: string; } | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
Returns
Returns a representation of a Basket object.
Referenced Types
ShipmentCreateParamsShopperBaskets.Basket
Examples
Creating a shipment by shipmentId.
import { sdk } from '~/sdk.config.ts';
const basket = await sdk.commerce.createShipment({
shipmentId: 'myShipmentId'
});Creating a shipment with shipping address by shipmentId.
import { sdk } from '~/sdk.config.ts';
const basketId = (await sdk.commerce.getBasket()).basketId;
const basket = await sdk.commerce.createShipment({
basketId,
shipmentId: 'myShipmentId',
shippingAddress: {
firstName: 'Ward J',
lastName: 'Adamek',
address1: '4911 Lincoln Street',
city: 'IDANHA',
postalCode: '97350',
stateCode: 'OR',
countryCode: 'US'
}
});Creating a shipment with shipping method by shipmentId.
import { sdk } from '~/sdk.config.ts';
const basketId = (await sdk.commerce.getBasket()).basketId;
const basket = await sdk.commerce.createShipment({
basketId,
shipmentId: 'myShipmentId',
shippingMethod: {
id: '003'
}
});Creating a shipment as a gift for a basket by shipmentId and shippingMethod.
import { sdk } from '~/sdk.config.ts';
const basketId = (await sdk.commerce.getBasket()).basketId;
const basket = await sdk.commerce.createShipment({
basketId,
shipmentId: 'shipmentId',
gift: true,
giftMessage: 'Happy Birthday'
});