This is a great question, and it's a hurdle many of us have had to clear. The Simpro API handles this in a specific way.
You're correct that there isn't a single global endpoint like /api/v1.0/companies/0/sitecontacts/ to get every site contact at once. Site Contacts are considered children of a specific Site. Therefore, to get all of them, you first need to get all the Sites and then loop through them to get their associated contacts.
Regarding the 250-item limit, you've correctly identified that the API uses pagination. You need to make multiple requests, incrementing the page number each time, until you get an empty response.
Here’s a step-by-step guide and some pseudo-code to solve this:
Step 1: Fetch All Site IDs with Pagination
First, you need to loop through the /sites/ endpoint to collect a list of all Site IDs.
Code: Select all
// Pseudo-code for getting all Site IDs
all_site_ids = []
current_page = 1
keep_fetching = true
while (keep_fetching) {
// Make the API call for the current page
api_url = "https://{your_build}.simprosuite.com/api/v1.0/companies/0/sites/?page=" + current_page
response = GET(api_url)
if (response is not empty) {
// Add the Site IDs from this page to your master list
for each site in response {
add site.ID to all_site_ids
}
// Go to the next page for the next loop
current_page = current_page + 1
} else {
// The response was empty, so we've reached the last page
keep_fetching = false
}
}
Step 2: Loop Through Site IDs to Get Contacts
Now that you have your complete list of all_site_ids, you can loop through that list and make a request to the contacts endpoint for each site.
Code: Select all
// Pseudo-code for getting contacts from each site
all_site_contacts = []
for each site_id in all_site_ids {
// Make the API call to the site's contacts endpoint
api_url = "https://{your_build}.simprosuite.com/api/v1.0/companies/0/sites/" + site_id + "/contacts/"
response = GET(api_url)
if (response is not empty) {
// Add the returned contacts to your final list
add response to all_site_contacts
}
}
// Now, 'all_site_contacts' contains every site contact from your build.
This two-step process is the standard way to pull complete lists of nested resources from the API. It can seem a bit long-winded, but it's reliable.
Hope this helps you get the data you need!