If you loop over WordPress posts through the REST API, you need to know when to stop. Guessing page numbers until you hit an error is the lazy way. The response already carries the answer, just not in the JSON body.
curl -s -D - -o /dev/null "https://example.com/wp-json/wp/v2/posts?per_page=100"
The -D - part dumps the response headers to the terminal and -o /dev/null throws the body away. Look for two headers. X-WP-Total is the total number of records in the collection, and X-WP-TotalPages is the number of pages that holds them at your current per_page.
Add | grep -i '^x-wp-total' and you get just those two lines. A script can read X-WP-TotalPages once and then request page=1 up to that number.
The paging parameters are simple. per_page takes a number from 1 to 100, and the docs say it is capped at 100 records. page picks the page. offset starts at an arbitrary record, and the docs give the equivalence ?per_page=5&page=4 is the same as ?per_page=5&offset=15.
One caveat: the docs state the cap but not the default page size, only that endpoints return a limited number of items per request. Don’t assume you got everything from a plain request without per_page. Check X-WP-TotalPages first.
Further reading: Pagination