Skip to content

Latest commit

 

History

History
380 lines (304 loc) · 20.5 KB

README.md

File metadata and controls

380 lines (304 loc) · 20.5 KB

Orders

(orders)

Overview

An order is a request from a customer to purchase goods from a merchant. Use the orders object to load orders from your system to the Shippo dashboard. You can use the orders object to create, retrieve, list, and manage orders programmatically. You can also retrieve shipping rates, purchase labels, and track shipments for each order.

Line Item


Line Items, and their corresponding abstract Products and Variants, might be exposed as a separate resource in the future. Currently it's a nested object within the order resource.

A line item is an individual object in an order. For example, if your order contains a t-shirt, shorts, and a jacket, each item is represented by a line item.

Available Operations

  • list - List all orders
  • create - Create a new order
  • get - Retrieve an order

list

Returns a list of all order objects.

Example Usage

import { Shippo } from "shippo";

const shippo = new Shippo({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const result = await shippo.orders.list({
    orderStatus: [
      "PAID",
    ],
    shopApp: "Shippo",
  });
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { ShippoCore } from "shippo/core.js";
import { ordersList } from "shippo/funcs/ordersList.js";

// Use `ShippoCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const shippo = new ShippoCore({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const res = await ordersList(shippo, {
    orderStatus: [
      "PAID",
    ],
    shopApp: "Shippo",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.ListOrdersRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.OrderPaginatedList>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

create

Creates a new order object.

Example Usage

import { Shippo } from "shippo";

const shippo = new Shippo({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const result = await shippo.orders.create({
    currency: "USD",
    notes: "This customer is a VIP",
    orderNumber: "#1068",
    orderStatus: "PAID",
    placedAt: "2016-09-23T01:28:12Z",
    shippingCost: "12.83",
    shippingCostCurrency: "USD",
    shippingMethod: "USPS First Class Package",
    subtotalPrice: "12.1",
    totalPrice: "24.93",
    totalTax: "0.0",
    weight: "0.4",
    weightUnit: "lb",
    fromAddress: {
      name: "Shwan Ippotle",
      company: "Shippo",
      street1: "215 Clayton St.",
      street3: "",
      streetNo: "",
      city: "San Francisco",
      state: "CA",
      zip: "94117",
      country: "US",
      phone: "+1 555 341 9393",
      email: "[email protected]",
      isResidential: true,
      metadata: "Customer ID 123456",
      validate: true,
    },
    toAddress: {
      name: "Shwan Ippotle",
      company: "Shippo",
      street1: "215 Clayton St.",
      street3: "",
      streetNo: "",
      city: "San Francisco",
      state: "CA",
      zip: "94117",
      country: "US",
      phone: "+1 555 341 9393",
      email: "[email protected]",
      isResidential: true,
      metadata: "Customer ID 123456",
      validate: true,
    },
    lineItems: [
      {
        currency: "USD",
        manufactureCountry: "US",
        maxDeliveryTime: new Date("2016-07-23T00:00:00Z"),
        maxShipTime: new Date("2016-07-23T00:00:00Z"),
        quantity: 20,
        sku: "HM-123",
        title: "Hippo Magazines",
        totalPrice: "12.1",
        variantTitle: "June Edition",
        weight: "0.4",
        weightUnit: "lb",
      },
    ],
  });
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { ShippoCore } from "shippo/core.js";
import { ordersCreate } from "shippo/funcs/ordersCreate.js";

// Use `ShippoCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const shippo = new ShippoCore({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const res = await ordersCreate(shippo, {
    currency: "USD",
    notes: "This customer is a VIP",
    orderNumber: "#1068",
    orderStatus: "PAID",
    placedAt: "2016-09-23T01:28:12Z",
    shippingCost: "12.83",
    shippingCostCurrency: "USD",
    shippingMethod: "USPS First Class Package",
    subtotalPrice: "12.1",
    totalPrice: "24.93",
    totalTax: "0.0",
    weight: "0.4",
    weightUnit: "lb",
    fromAddress: {
      name: "Shwan Ippotle",
      company: "Shippo",
      street1: "215 Clayton St.",
      street3: "",
      streetNo: "",
      city: "San Francisco",
      state: "CA",
      zip: "94117",
      country: "US",
      phone: "+1 555 341 9393",
      email: "[email protected]",
      isResidential: true,
      metadata: "Customer ID 123456",
      validate: true,
    },
    toAddress: {
      name: "Shwan Ippotle",
      company: "Shippo",
      street1: "215 Clayton St.",
      street3: "",
      streetNo: "",
      city: "San Francisco",
      state: "CA",
      zip: "94117",
      country: "US",
      phone: "+1 555 341 9393",
      email: "[email protected]",
      isResidential: true,
      metadata: "Customer ID 123456",
      validate: true,
    },
    lineItems: [
      {
        currency: "USD",
        manufactureCountry: "US",
        maxDeliveryTime: new Date("2016-07-23T00:00:00Z"),
        maxShipTime: new Date("2016-07-23T00:00:00Z"),
        quantity: 20,
        sku: "HM-123",
        title: "Hippo Magazines",
        totalPrice: "12.1",
        variantTitle: "June Edition",
        weight: "0.4",
        weightUnit: "lb",
      },
    ],
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request components.OrderCreateRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.Order>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

get

Retrieves an existing order using an object ID.

Example Usage

import { Shippo } from "shippo";

const shippo = new Shippo({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const result = await shippo.orders.get("<value>");
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { ShippoCore } from "shippo/core.js";
import { ordersGet } from "shippo/funcs/ordersGet.js";

// Use `ShippoCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const shippo = new ShippoCore({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const res = await ordersGet(shippo, "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
orderId string ✔️ Object ID of the order
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.Order>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /