Are you going to AU Las Vegas? If so, my class on InfraWorks 360 API - Sharing Model and Proposal Data will be Thursday, Dec 3rd, 3pm. If you cannot attend, here is the handout, enjoy.
1. Start developing apps based on InfraWorks 360 REST API
To start developing with the REST API, first there are some required background topics. This material will not cover them in deep, but there are lots of resources on the web.
Required Software and Libraries
First it’s required to have models on your account, so you should install InfraWorks 360 and create a model that will be accessed via API. If the model is created locally, it must be synched to the Autodesk Cloud, only then it will be accessible via API. As expected, any local change will not be visible via API until the model is synched again.
The communication code can be written in any language that has support for REST protocols. In fact, as REST is language agnostic, any language should work, but not every language have the libraries to do so. Most modern languages are natively compatible or have libraries to do so. For instance, in .NET, the RestSharp (http://restsharp.org) should have all the main features.
The response will come in plain text formatted as JSON. Although we can read it (human-readable), it’s easier to deserialize into objects on your preferred language. From JSON to .NET Objects, for instance, the Newtonsoft.JSON library (https://www.nuget.org/packages/Newtonsoft.Json ) can do the trick. To clarify, deserialize is the process of converting an object stored into an object in memory. For this process, we need the classes representing the JSON structure. We provide that class structure in .NET (we’ll talk about sample later in this material), just like many other libraries for other APIs.
The samples presented here were developed using .NET with Visual Studio, which is the same developing language supported for AutoCAD Civil 3D (and for other Autodesk desktop prodcuts). This language was selected by convenience and any other language with support for REST should work.
2. Discover the data structure of the API
The API structure is basically the same as the product: for each account, there are models that represent a specific area and contains one or more proposals, with different designs for that specific area, then the features, such as road, buildings, trees, etc.
On the API perspective, the first level resides at https://api.infraworks.autodesk.com, but it doesn’t contain relevant model information, just some basic server information.
The first URL level to provide information is https://api.infraworks.autodesk.com/models and contains a list of models for the logged user, as shown on the example below. Note the id and name of each model, and the model id will be used on the next calls.
Using the model id, the response from https://api.infraworks.autodesk.com/models/:model_id will contain the name, boundary, list of proposals, among other properties. Below is a sample reply:
To access a specific proposal, we will need the model_id along with the proposal_name, obtained on the model level. The URL is https://api.infraworks.autodesk.com/models/:model_id/propsals/:proposal_name. As we can see, each level uses a URL build on top of the previous level URL.
Below is a sample response for a proposal call (end-point). Note the list of available features at the bottom, the href parameter contains the URL for each feature collection.
At this level we can access the items (features) placed on the model’s proposal. The URL consists in https://api.infraworks.autodesk.com/models/:model_id/proposals/:proposal_name/:feature_type/ and contains the model_id, the proposal_name and, finally, the feature_type, which will return a list of features.
The feature types can be:
• City furniture
• Constraint definition
• Horizontal and Vertical constraint
• Intersection and Intersection region
• Pipe connector and Pipeline
• Point clouds
• Points of Interest (POI)
• Terrain surface and texture
Full list here. After the list, next step is read the feature data itself. Each different feature will have different information, but the calling URL should be in the same format, using the model_id, proposal_name, feature_type and the its id: http://api.infraworks.autodesk.com/models/:model_id/proposals/:proposal_name/:feature_type/:id. Here is a sample response for a tree feature type:
Some feature properties are expected for all types of features, such as revision and id.
Learn how to make calls to InfraWorks 360 REST API
InfraWorks 360 REST API uses the OAuth 2.0 authentication, that requires a key & secret on the developer side, plus a user login & password on the user side. The developer authentication is required to increase security and avoid attacks to Autodesk servers. The user authentication certifies confidentially of each user’s information.
The first step is authenticate using the developer key & secret on https://accounts.autodesk.com server, which will return a authorization token, allowing access to the API. With this token, your application can ask the user to login on the same server and, if ok, will return a verifier, that allows access to the user’s data. This process is known as “2 legged authentication” and is required because a developer and the user are different personas, and both need to authorization, to use the API and read the data.
All requests to the InfraWorks 360 REST API must have a header indicating the type of response required. If not, the server will automatically redirect to the documentation (and will not return API data). The header should include (along with the authentication token) the following “Accept” requirement:
With this header, we just need to connect to the server using the URLs described on the previous topic. Each request will require a different URL (end-point). For instance, to get a model with ID 1234, make a request with /models/1234.
In C# .NET, using RestSharp and Newtonsoft.JSON libraries, it would be like:
// Required since relase May/2015 – TLS 1.2
// base client URL
RestClient client = new RestClient("https://api.infraworks.autodesk.com");
// consumer key & secret + authorization tokens
OAuth1Authenticator authenticator = OAuth1Authenticator.ForProtectedResource(
consumerKey, consumerSecret, accessToken, accessTokenSecret);
client.Authenticator = authenticator;
// resource we need to access
RestRequest request = new RestRequest("/models/1234", Method.GET);
request.RequestFormat = DataFormat.Json;
// make the call
IRestResponse response = client.Execute(request);
// treat the results
if (response.StatusCode == System.Net.HttpStatusCode.OK)
string json = response.Content;
// deserialize the JSON return into objects in .NET
return JsonConvert.DeserializeObject(json, typeof(Model));
// many problems can happen...treat error here
Note this is just a schematic, on a real application, this should be optimized (reuse variables) and adjusted according to each scenario. See next section for more sample code.
Discover sample scenarios of integration
There is a huge number of webservices available on the web, providing all types of data. Most likely, your application will collect data from different sources and mashup different providers and create a unique interface.
How we can we mashup webservices?
First we need to find out what makes sense. As InfraWorks 360 store geolocated city design information, it’s make sense to link to other geolocated data. There is an extensive catalog of webservice APIs at the Programmable Web, check the Mapping and Geography categories for interesting providers.
InfraWorks 360 + Four Square + Google Maps
This sample was originally presented at this blog post and now updated. It reads the buildings of the InfraWorks 360 model and, using the location information, asks the Four Square API for nearby venues. The result is shown at a Google Maps with the InfraWorks 360 location of the building and the Four Square location of the venue found and selected.
Just like Autodesk Cloud APIs, to use Four Square API you will need a key & secret. To get more information about their API program, please visit here. Below is a quick print-screen of the sample running. To use it with your personal account, please visit here. and login with your Autodesk Account (the same used on InfraWorks 360). Note that you must have at least 1 model on that account. The source code is available at the sample sample page.
InfraWorks 360 + Google Maps
After some searching, I found the John Dyer blog with a nice sample: Drawing 3D Objects and Buildings on Google Maps. After reading and understanding the code, you will see that it is actually a 2 + ½ D, not actually a 3D: the buildings are drawn in perspective to look like 3D.
Using InfraWorks 360 building polygon information and John Dyer’s code to draw the buildings, the result will be like shown below:
And you can try with your models (using your Autodesk Account with InfraWorks 360 models) at this link.
InfraWorks 360 + AutoCAD Civil 3D
Sure we can also integrate with AutoCAD Civil 3D. As you may know some integration is already available via Productivity Pack, but this is just to demonstrate the idea.
This sample demonstrating how bring InfraWorks 360 Roads into AutoCAD Civil 3D as Alignments is available at the Importing Alignment from InfraWorks 360 to AutoCAD Civil 3D blog post and was also the sample presented at my Autodesk University 2014 class SD6503.