C# API Client

The Project Insight API C# Client is the easiest way to access the Project Insight API (REST) services in a .NET development environment. To use the Project Insight API C# Client, you must download the assemblies, obtain an API Token, and have a valid user account for your instance of Project Insight. The URL for the API for your site, the assemblies, and your API Token is available within your Project Insight instance in the Administration » Integration » API (REST) menu.

Prior to beginning, you may want to review the Project Insight Web API Client documentation and the Getting Started guide.

Once you have downloaded the assemblies, add them as a reference to your .NET project. To begin working with the Project Insight API C# Client use the following syntax:

		using ProjectInsight.WebApi.Client;

		// Set the connection security to allow TLS 1.1 and TLS 1.2
		System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
		ProjectInsightWebApiClient client = 
			new ProjectInsightWebApiClient("http://yourdomain.projectinsight.net/api", "{api-token}");			
Creating a client object to access independent clients by function as well as invoke methods from those clients. NOTE: The API requires TLS 1.2 so enable that protocol as illustrated above.

Let's create some List objects from the Project Insight Model class and retrieve the objects in a collection.

		using System;
		using System.Collections.Generic;
		using ProjectInsight.Models.Projects;

		List<Project> projects = client.Project.Active();
Returning a collection of active projects.


		using System;
		using System.Collections.Generic;
		using ProjectInsight.Models.Users;

		List<User> users = client.User.ListActive();
Returning a collection of active users.

The "client" functions are listed under the ProjectInsight.WebApi.Client Assembly. Models returned by the API are listed in the ProjectInsight.Models Assembly, which inherit from the Base model assembly. All of these assemblies are documented in this library.

C# API (REST) Client Tester

You can use the Project Insight C# API (REST) Client Tester tool to validate and test objects. This is beneficial, if you'd like to define specific properties to output for each object model that will be returned.

You can invoke the method of the object with specified modelProperties using the client tester.

Note: Model Properties allow you to define the specific properties to output for each object model returned. You may supply JSON, or a string formatted like: "Type1:default,Property1,Property2;Type2:Property3,Property4,Type3:all". Keywords "default" return default properties, "all" returns all properties, excluding properties which are lists of child objects. You do not need to specify the type.

Online 12/9/2016