ConnectWise.Http 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package ConnectWise.Http --version 1.0.6                
NuGet\Install-Package ConnectWise.Http -Version 1.0.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ConnectWise.Http" Version="1.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ConnectWise.Http --version 1.0.6                
#r "nuget: ConnectWise.Http, 1.0.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ConnectWise.Http as a Cake Addin
#addin nuget:?package=ConnectWise.Http&version=1.0.6

// Install ConnectWise.Http as a Cake Tool
#tool nuget:?package=ConnectWise.Http&version=1.0.6                

ConnectWise.Http

A .NET HttpClient wrapper for interacting with the ConnectWise Manage REST API.

Installation

NuGet PM> Install-Package ConnectWise.Http

Usage

Client Setup

using ConnectWise.Http;

// Create Settings
var settings = new CWApiSettings(
  "https://cw.siteurl.com",
  "companyName",
  new MemberAuthSettings("publicKey", "privateKey")
  );

// Create HTTP Client
var client = new CWHttpClient(settings);
Providing an existing HttpClient

There is also an overloaded constructor that allows you to provide an existing instance of an HttpClient, so that CWHttpClient does not create its own HttpClient instance. It is generally good practice to only construct & use a single HttpClient instance throughout the lifetime of your application (with some exceptions relating to when DNS changes are made during the lifetime of your application) - this is because each HttpClient constructed will claim a web socket.

So, provide an HttpClient instance to CWHttpClient, which exclusively uses the HttpClient.SendAsync(HttpRequestMessage message) method so that you don't need to worry about CWHttpClient making any changes to the default settings of the HttpClient that you provided.


GET Request

using ConnectWise.Http.Modules.Service;

// Build & Send Request
int ticketId = 121;
var request = ServiceModule.Tickets.GetRequest(ticketId);
var response = await client.SendAsync(request);

POST/PUT Request

You serialize the body content before building the request.

// Build & Send Request
string serializedContent = JsonConvert.SerializeObject(...);
var request = ServiceModule.Tickets.CreateRequest(serializedContent);
var response = await client.SendAsync(request);

PATCH Request

ConnectWise.Http provides a ConnectWise Patch Operation object as per their REST developer documentation.

// List Patch Operations
var operations = new List<CWPatch>();
operations.Add(new CWPatch {
  Op = CWPatchOperation.Replace,
  Path = "status/name",
  Value = "Closed"
  });
  
// Build & Send Request
int ticketId = 121;
var request = ServiceModule.Tickets.UpdateRequest(ticketId, operations);
var response = await client.SendAsync(request);

Deserialization

Once you have your response, the CWResponse object can attempt to deserialize to your specified class type.

// Where "TConnectWiseTicket" is your custom type.
int ticketId = 121;
var request = ServiceModule.Tickets.GetRequest(ticketId);
var response = await client.SendAsync(request);

// Using Deserialize
// An exception will be thrown if deserialization fails
var ticketOne = response.Deserialize<TConnectWiseTicket>();

// Using TryDeserialize
if (response.TryDeserialize<TConnectWiseTicket>(out TConnectWiseTicket ticketTwo) {
  // Do something with ticketTwo
} else {
  var exception = response.DeserializationException;
  // Error Logging
}

Modules

Below are the modules currently implemented. You can use the CWRequest object to specify specific endpoints not yet supported here - These serve only to simplify the creation of the request URI.

Modules Supported
Company Yes
Expense Yes
Finance Yes
Marketing No
Procurement No
Project Yes
Sales No
Schedule Yes
Service Yes
System Partial
Time Yes
Product Compatible and additional computed target framework versions.
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 22,321 8/22/2019
1.1.0 1,487 7/14/2019
1.0.9 2,567 10/1/2018
1.0.8 1,905 5/24/2018
1.0.7 1,817 5/24/2018
1.0.6 1,807 5/22/2018
1.0.5 1,889 4/30/2018
1.0.4 1,967 4/27/2018
1.0.3 1,772 4/26/2018
1.0.2 2,160 12/10/2017
1.0.0.1 1,821 11/22/2017
1.0.0 1,902 11/22/2017

Resolved bugs with 'Fields' & 'Columns' properites of CWRequestConditions not being written correctly into request URL. Added Finance Module & added Members endpoint for Systems Moduel.