Im sure this is in here, I havent be able to find it and I did a bit of a search. Sorry if it is can you link me?
We are trying to use a GET for a list of Site Contacts with the API. I am able to get a Company Contact with /api/v1.0/companies/0/contacts but is there one for the Site Contact?
I am also seeing it maxes out at 250 pages. Is there a way to get more than that?
Basically, we need to pull all the site contacts for a POST in another platform.
HELP PLEASE!
API GET all Site Contacts
Forum rules
- Check the documentation first. Before posting questions, please check the documentation to ensure it doesn't already cover what you need.
- No spam. All automated messages, advertisements, and links to competitor websites will be deleted immediately.
- Post in relevant sub-forums only. Messages posted in the wrong topic area will be removed and placed in the correct sub-forum by moderators.
- Respect other users. No flaming or abusing fellow forum members. Users who continue to post inflammatory, abusive comments will be deleted from the forum after two warnings are issued by moderators.
- Harassment. No threats or harassment of other users will be tolerated. Any instance of threatening or harassing behavior is grounds for deletion from the forums.
- Adult content. No profanity or pornography is allowed. Posts containing adult material will be deleted.
- Bandwidth. All images and signatures must be 500 x 500 pixels or smaller. Posts containing over-sized images and signatures will be removed.
- Illegal content. No re-posting of copyrighted materials or other illegal content is allowed. Any posts containing illegal content or copyrighted materials will be deleted.
Re: API GET all Site Contacts
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.
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.
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!
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
}
}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.Hope this helps you get the data you need!
Re: API GET all Site Contacts
Awesome! Thank you! I’ll give it a try!
Thanks so much!
Thanks so much!
Re: API GET all Site Contacts
Does anyone else use n8n for this type of integration?
If not, what are you guys using. I've only beeing doing this for about a yer and Im still learning!
Thanks for all the help!
If not, what are you guys using. I've only beeing doing this for about a yer and Im still learning!
Thanks for all the help!
DEVELOPER CENTER