When the REST API returns a model, it only includes a default subset of available properties. This is by design. You can customize the included properties by using the optional ModelProperties object parameter when interacting with most methods in the REST API.

The ModelProperties is an optional parameter on most REST calls. The ModelProperties model contains a property, ModelPropertyLists, which is a list of ModelPropertyList models. Each ModelPropertyList model (multiple properties are included) allows you to define the properties to include for a specific model type.

For example, if you make a request which includes a list of Task models, you can create a ModelPropertyList and add it to the ModelProperies model and define the specific properties to include in the response. If the response includes a related model, like Task.Project, then you can add a ModelPropertyList model for the Project type to define the properties to return for any Project model in the response.

Default Properties

In order to simplify API responses, the Project Insight REST API uses a specialized param named 'modelProperties'. By default, this will return a set of default properties on the model object.

cURL

	curl -X GET --header 'Accept: application/json' 
	'https://yourdomain.projectinsight.net/api/task/{id}'


Response Body

	[{
		"ProjectType_Id": null,
		"ProjectStatus_Id": null,
		"CompanyDefault_Id": null,
		"Department_Id": null,
		"ProjectState": 0,
		"ScheduleStartDate": "2014-10-28T00:00:00",
		"DurationSeconds": 0,
		"WorkSeconds": 0,
		"StartDateTimeUTC": "2014-10-28T15:00:00Z",
		"EndDateTimeUTC": "2014-10-28T15:00:00Z",
		"WorkPercentComplete": 0.00,
		"CustomFieldValue_Id": null,
		"Name": "MS Project Imported Tasks - Conversion Service Test 1",
		"Id": "6d02dbe0-6cfe-4dc9-ba31-b6e6a370c740",
		"IdExternal": null
	}]

By default, the JSON returns the properties set within the model for the task object.

Selecting Properties

You can limit properties returned from the Response Body. To specify the fields returned, set the valid property names in the parameter, which is set on the model properties object. This will increase performance and give you control over what the response object returns.

cURL

	curl -X GET --header 'Accept: application/json' 
	'https://yourdomain.projectinsight.net/api/task/{id}?
	modelProperties=wbscode,issummarytask,workhours,id,startdatetimeutc,name'


Response Body

	{
		"WBSCode": "2",
		"IsSummaryTask": false,
		"WorkHours": 16.00,
		"StartDateTimeUTC": "2014-07-18T15:00:00Z",
		"Name": "Task #1",
		"Id": "8baa41ef-c610-42a5-851d-ea2447899dc1",
		"IdExternal": null
	}

Project Insight only returns the properties we passed into the modelProperties parameter.

After limiting which properties on the object model are returned, you can also request a strongly typed model object and its properties. You may supply JSON, or a string, formatted like: "Type1:default,Property1,Property2;Type2:Property3,Property4,Type3:all".

This snippet will request only the specified properties and types passed in as a parameter.

cURL

	curl -X GET --header 'Accept: application/json' 
' https://yourdomain.projectinsight.net /api/task/{id}?modelProperties=wbscode,issummarytask,workhours,id,startdatetimeutc,name,project;project:name,startdatetimeutc,description'


Response Body

{
	  "Project": {
		"StartDateTimeUTC": "2014-07-16T15:00:00Z",
		"Name": "Test - 4483: Search does not find words in imported tasks",
		"Description": "This is description for this project",
		"Id": "5fe47639-2c31-4fd8-ab05-f2e984f264f2",
		"IdExternal": null
	  },
	  "WBSCode": "2.3",
	  "IsSummaryTask": false,
	  "WorkHours": 16,
	  "StartDateTimeUTC": "2014-07-18T15:00:00Z",
	  "Name": "Task #1",
	  "Id": "45d7b437-7a5e-4af2-9801-461bbf068bca",
	  "IdExternal": null
}

The application only returns the specified object types with the properties we passed into the modelProperties parameters.

Limitations of "All" and "Default"

Usingall as the ModelProperties parameter of the Task object will ask the API to return all default properties on the object model.

PI will not return list and collection type model objects if you use both keywords. You will need to explicitly request list and collection types related on the object model for PI to return your desired response. If you pass the 'type' as "default", we will return the default properties on the object model.

cURL

	curl -X GET --header 'Accept: application/json' 
	'https://yourdomain.projectinsight.net/api/task/{id}?modelProperties=all'


Response Body

	{
		"SummaryTask_Id": null,
		"Project_Id": "8cb100d0-301a-4593-a1d4-cfe0978ab43a",
		"Project": {
			"ProjectType_Id": null,
			"ProjectStatus_Id": null,
			"CompanyDefault_Id": null,
			"Department_Id": null,
			"ProjectState": 0,
			"ScheduleStartDate": "2014-09-23T00:00:00",
			"DurationSeconds": 1684800,
			"WorkSeconds": 475200,
			"StartDateTimeUTC": "2014-07-16T15:00:00Z",
			"EndDateTimeUTC": "2014-10-06T19:00:00Z",
			"WorkPercentComplete": 0.00,
			"CustomFieldValue_Id": null,
			"Name": "Test #3 - 4483: Search does not find words in imported tasks",
			"Id": "8cb100d0-301a-4593-a1d4-cfe0978ab43a",
			"IdExternal": null
		},
		"ResourceType_Id": null,
		"WBSCode": "2",
		"OrderInt": 1,
		"TaskProcessAdjustmentType": 0,
		"IsMilestone": false,
		"IsSummaryTask": false,
		"ConstraintDate": "2014-07-18T08:00:00",
		"ConstraintType": 4,
		"DeadlineDate": "2014-07-18T00:00:00",
		"DurationIsElapsed": false,
		"TaskProcessAdjustmentTypeDefault": 1,
		"DurationSeconds": 57600,
		"WorkSeconds": 57600,
		"WorkHours": 16.00,
		"StartDateTimeUTC": "2014-07-18T15:00:00Z",
		"EndDateTimeUTC": "2014-07-22T00:00:00Z",
		"WorkPercentComplete": 0.00,
		"WorkPercentCompleteType_Id": "b26b93d3-693b-4287-aaaf-ad92d7a2f265",
		"WorkPercentCompleteType": {
			"Name": "Not Started",
			"WorkPercentComplete": 0.00,
			"DisplayOrder": 0,
			"IsActive": true,
			"Id": "b26b93d3-693b-4287-aaaf-ad92d7a2f265",
			"IdExternal": null
		},
		"ActualStartDateTimeUTC": null,
		"ActualEndDateTimeUTC": null,
		"ItemContainer_Id": "8cb100d0-301a-4593-a1d4-cfe0978ab43a",
		"UserCreated_Id": "ca76178f-862a-4598-a1c9-afdb98148660",
		"UserCreated": {
			"FirstName": "Robert",
			"LastName": "Aronovici",
			"Id": "ca76178f-862a-4598-a1c9-afdb98148660",
			"IdExternal": null
		},
		"UserUpdated_Id": "ca76178f-862a-4598-a1c9-afdb98148660",
		"UserUpdated": {
			"FirstName": "Robert",
			"LastName": "Aronovici",
			"Id": "ca76178f-862a-4598-a1c9-afdb98148660",
			"IdExternal": null
		},
		"UserAssignedBy_Id": "ca76178f-862a-4598-a1c9-afdb98148660",
		"UserAssignedBy": {
			"FirstName": "Robert",
			"LastName": "Aronovici",
			"Id": "ca76178f-862a-4598-a1c9-afdb98148660",
			"IdExternal": null
		},
		"CustomFieldValue_Id": null,
		"ItemNumber": null,
		"ItemNumberAlt": "",
		"ItemNumberCombined": "18.00002",
		"Name": "Task #1",
		"Url": "/task/8baa41efc61042a5851dea2447899dc1",
		"UrlMobile": "/m/taskdisplay.aspx?id=8baa41ef-c610-42a5-851d-ea2447899dc1",
		"Description": "",
		"Id": "8baa41ef-c610-42a5-851d-ea2447899dc1",
		"IdExternal": null
	}

PI returns all properties including related objects with their properties.

ModelProperties

Example of the ModelPropertyList:


	curl -X GET --header 'Accept: application/json' 
	'https://yourdomain.projectinsight.net/api/task/{id}?
	modelProperties=wbscode,issummarytask,workhours,id,startdatetimeutc,name'


Response Body

	{
		“ModelPropertyLists”:[
		{
		   “ObjectType”: “Project”,
		   “Properties”: “Name, WorkHours,ItemNumber,Description”
		}]
	}

An example of a generated JSON ModelPropertyLists object.

C#

	//Set properties to return in model
	ModelProperties props = new ModelProperties();
	props.AddModelPropertyList("projectresources,tasks;projectresource:isprojectmanager,actualhours;task:issummarytask,name,tasks,TaskResources");

        Project myProject = this.client.Project.Get("b11976d9-011a-4f56-a792-074735d4acf3", props);

Creating a ModelProperties object and adding values to the collection.
Online 12/9/2016