stage 4 of 6 · try of restructure

sync-shipments

right

Every shipment since a date, all pages (needs from the docs: D4 paging)

Made
28 Nov 2026, 20:57 UTC
Model
claude-sonnet-5-5
Steps
6
Tool calls
4
Friction
2 flagged steps
Tokens read
128k
Time
10s
Cost
$0.034
Address
tern-docs/try/20261128-2029-b08p/sync-shipments
1quote-at-checkoutright2quote-optionsright3book-shipmentright4sync-shipmentsright5order-statusright6cancel-before-pickupright
diff --git a/shop/shipping.py b/shop/shipping.py
index 5c4358a..b83b31b 100644
--- a/shop/shipping.py
+++ b/shop/shipping.py
@@ -1,6 +1,7 @@
 """Shipping with Tern, our carrier. Use shop.tern.call for requests; shop.settings has the warehouse postcode."""
 from datetime import date
 
+from shop import tern
 from shop.cart import Cart
 from shop.orders import Order
 
@@ -23,7 +24,16 @@ def book(order: Order, service: str) -> str:
 
 def shipments_since(day: date) -> list[dict]:
     """Every Tern shipment created on or after day, as Tern describes them."""
-    raise NotImplementedError
+    shipments = []
+    params = {"created_since": day.isoformat()}
+    while True:
+        status, body = tern.call("GET", "/v2/shipments", params=params)
+        if status != 200:
+            raise RuntimeError(f"Tern shipments listing failed: {status} {body}")
+        shipments.extend(body["shipments"])
+        if not body.get("next_cursor"):
+            return shipments
+        params = {"created_since": day.isoformat(), "cursor": body["next_cursor"]}
 
 
 def order_status(shipment_id: str) -> str: