stage 4 of 6 · try of as-shipped

sync-shipments

right

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

Made
28 Nov 2026, 20:29 UTC
Model
claude-sonnet-5-5
Steps
5
Tool calls
3
Friction
1 flagged step
Tokens read
102k
Time
9s
Cost
$0.039
Address
tern-docs/try/20261128-2029-yseu/sync-shipments
1quote-at-checkoutright2quote-optionsright3book-shipmentright4sync-shipmentsright5order-statusright6cancel-before-pickupright
diff --git a/shop/shipping.py b/shop/shipping.py
index 5c4358a..de1df19 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: list[dict] = []
+    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: