Export every roof measurement to a spreadsheet with the API: paging through results and rate limits
A short Python script that walks every measurement in a RoofStruct account, writes squares, pitch and lengths to a CSV, respects the rate limit, and runs nightly.
To put every roof you've measured into one spreadsheet, list measurements from GET /v1/projects 100 at a time, following next_cursor until it's null, read each one's numbers from /v1/projects/{id}/measurements, and write a CSV row per roof. Respect the 120-requests-a-minute limit by waiting when you get a 429, and run it nightly.
The script
Python 3 with the requests library. Set ROOFSTRUCT_API_KEY to a key from Settings › Integrations › API & Webhooks (how to make one).
import csv, os, time
import requests
BASE = "https://roofstruct.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['ROOFSTRUCT_API_KEY']}"}
def get(path, params=None):
while True:
r = requests.get(f"{BASE}{path}", headers=HEADERS, params=params, timeout=30)
if r.status_code == 429:
time.sleep(int(r.headers.get("Retry-After", "60")))
continue
r.raise_for_status()
return r.json()
def all_projects(updated_since=None):
params = {"limit": 100}
if updated_since:
params["updated_since"] = updated_since
while True:
page = get("/projects", params)
yield from page["data"]
if not page["next_cursor"]:
break
params["cursor"] = page["next_cursor"]
FIELDS = ["reference", "name", "address", "updated_at", "roof_area_ft2",
"squares", "order_squares", "waste_percent", "pitch",
"eave_ft", "rake_ft", "ridge_ft", "hip_ft", "valley_ft"]
with open("roofs.csv", "w", newline="") as f:
out = csv.DictWriter(f, fieldnames=FIELDS)
out.writeheader()
for p in all_projects():
m = get(f"/projects/{p['id']}/measurements")["data"]["measurements"]
if not m or not m["calibrated"]:
continue # not drawn yet, or no scale
L = m["lengths_ft"]
out.writerow({
"reference": p["reference"], "name": p["name"],
"address": p["address"], "updated_at": p["updated_at"],
"roof_area_ft2": m["roof_area_ft2"], "squares": m["squares"],
"order_squares": m["order_squares"],
"waste_percent": m["waste_percent"],
"pitch": m["predominant_pitch_text"],
"eave_ft": L["eave"], "rake_ft": L["rake"], "ridge_ft": L["ridge"],
"hip_ft": L["hip"], "valley_ft": L["valley"],
})
Open roofs.csv in Excel or Google Sheets, or import it into your estimating spreadsheet.
How the paging works
The list returns newest first, with a next_cursor when there's more. Pass it back as cursor with the same filters, and stop when it comes back null. limit goes up to 100; at 100 per page, 1,000 measurements is 10 list calls.
The cursor is opaque. Don't build or edit one; just pass back what you were given.
Staying inside the rate limit
Each key gets 120 requests a minute. The script above makes one list call per 100 roofs plus one call per roof, so a run over 1,000 measurements is about 1,010 calls, or about nine minutes at 120 a minute. When it hits the limit, the API answers 429 with Retry-After, the script sleeps that long and carries on.
If another tool uses the same key, it shares the limit. Give the export its own key.
Make it nightly
Run the whole export each night from a scheduler (cron, a scheduled cloud function, or your server's task scheduler) after the office closes, and replace yesterday's file.
Don't shortcut it with updated_since on measurements. That filter follows the measurement's own details, such as its name and address, not its drawing, so a roof redrawn today wouldn't show up. To hear about finished drawings as they happen, add a webhook for Measurement Sent and have your team click Send Now when a drawing is done.
Where you trip
- Rows with empty numbers. A measurement without a scale returns
calibrated: falseandnullsizes. Skip it or mark it "not drawn". - Archived measurements. They aren't listed. A roof archived in RoofStruct drops out of the export.
- Reports. Done-for-you reports are a separate list:
GET /v1/reportsand/v1/reports/{id}/measurementsonce delivered. Add a second loop if you want them in the sheet. - Sharing one key across tools. The nightly export can starve a live integration of its 120 a minute.
Developer docs: List projects, Pagination and Get project measurements in the RoofStruct API reference.