Pull Office 365 Endpoint URLs via REST-based web service
The issue we faced
Since Office 365 is a cloud service, one of the first stages in every Office 365 project is to ensure network communication between your onpremise environment or your client network and Office 365. This includes proxy and firewall exclusions, while our main challenge was to maintain the constantly changing URLs, especially in the early stages of a new service. So here we had to find a solution for automation.
The solution we came up with
The good thing is that Microsoft provides a REST-based web service, from which you can pull all the current endpoint URLs. We used this webservice, to pull the endpoint URLs, filter them by the services and products we need and finally output an HTML file, which is published internally by a simple IIS. The final step is for the network appliance, say a web proxy, to fetch the HTML file and whitelist all the URLs. Your network appliance might not offer the functionality to fetch from a remote file, there's still a huge benefit to get all the necessary URLs in a few simple steps.
Here's how we did it
First up, for the API to associate the clients which call the web service, we need to generate a unique GUID for each machine that calls the web service. We do this by creating a new GUID and store it in a *.TXT file, which we query on each run:
In this example, we filter the endpoints by the services Exchange Online, Skype for Business Online and common URLs.
1. Get endpoint URLs from the REST-based web service
2. Filter by services:
3. Extract the URLs from the result objects:
You might need to further modify the results, to match the syntax of your network appliance. In our case we had to remove all the asterisk characters, because our web proxy hates them :-( So the last line before exporting the HTML file would be the following:
Reference: https://docs.microsoft.com/en-us/office365/enterprise/office-365-ip-web-service