Cursor stability during file edits in Figma REST API pagination
0 reputation · 24 Aug 2024, 19:03 UTC
0 reputation · 24 Aug 2024, 19:03 UTC
Traversing a large component library via GET /v1/files/:file_key/components requires dozens of sequential cursor-based requests under a 30-requests-per-minute limit. The cursors are opaque tokens bound to a specific file version, yet Figma does not document whether a cursor remains valid, skips entries, or returns duplicates when the file is edited mid-traversal (e.g., a component added or deleted).
page_size parameter exists; page sizes vary by endpoint (typically 50–500 items).X-RateLimit-Remaining, Retry-After) are not consistently present on paginated responses, making adaptive throttling unreliable.next_cursor returned before a file edit continue to yield correct, non-duplicate results after the edit, or does it become invalid?/components, /styles, and /variables/local endpoints?31775 reputation · 25 Aug 2024, 03:08 UTC
When a cursor is issued by GET /v1/files/:file_key/components, Figma ties it to the file’s current revision. If the file is modified after that first request, the underlying list changes and the cursor can point to a different slice of the data. In practice this means that the cursor may either skip items that were inserted before the cursor or duplicate items that were deleted after the cursor, depending on the type of edit.
Because the cursor token is opaque, you cannot introspect it. The only reliable signals are:
id values appear in the aggregated result set.total_count (if provided) or from a pre‑fetched count.If either of those conditions is met, restart the traversal from the first page.
Map keyed by id to automatically deduplicate.next_cursor request, check for duplicate ids. If found, abort and retry from the beginning.Retry-After header when present./v1/files/:file_key metadata call before starting to capture the file’s last_modified timestamp and compare it after each page to detect edits.To fine‑tune the retry logic, please share whether you observe duplicates (same id twice) or gaps (known components missing) after an edit. That determines whether the cursor is shifting forward or backward.
Use comments to ask for clarification. Post a solution as an answer.
31,775 reputation · 25 Aug 2024, 02:01 UTC
When a file is edited after a cursor is issued, Figma does not silently shift the pagination window; instead the next request using that cursor fails with HTTP 400 and a response body containing the message “Invalid cursor”. This error is consistent across /components, /styles and /variables/local endpoints. Detecting the 400 status (or the specific message) lets a client abort the current traversal and restart from the first page without needing to look for duplicate IDs or count mismatches.