Reputation: 1222
I intend to create a program using C# which will update tickets in ConnectWise using, eventually, data from another API.
Thus far I've wanted to test to GET
some invoices. For this I installed the latest SDK and referenced it in Visual studio (SDK 2017.3).
The documentation claims that this should suffice:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConnectWiseDotNetSDK;
using ConnectWiseDotNetSDK.ConnectWise;
using ConnectWiseDotNetSDK.ConnectWise.Client;
using ConnectWiseDotNetSDK.ConnectWise.Client.System.Api;
using ConnectWiseDotNetSDK.ConnectWise.Client.System.Model;
private static List<Invoice> getInvoices()
{
var client = getApiClient();
var invoicesApi = new InvoiceApi(client);
var response = invoicesApi.GetInvoices();
var invoices = response.GetResult<List<Invoice>>();
foreach (var invoice in invoices)
{
Console.WriteLine(invoice);
}
return invoices;
}
(where I have added all the using ....
rows, the documentation does not clarify which are needed).
This however gives me an error that getApiClient() does not exist in this context
. I reckon I must create the function, which will provide my authentication etc. Thus I've done:
private static getApiClient()
{
string BaseUri = "https://eu-myconnectwise.net/v4_6_Release/apis/3.0/finance/invoices"
string ContentType = "application/json";
string Authstring = "xxxxyyxxxx";
}
This does not work. I have no idea how to create the client
variable in the main program.
Has anyone gotten the SDK to work using C#?
Upvotes: 1
Views: 3269
Reputation: 21
Unfortunately, while the Connectwise documentation is getting better, there's still a whole heap of digging around that you have to do to get the end result you're after.
Here's a short example based on the ZIP file at the bottom of the answer.
const string cw_app_id = "<YourAppID>";
const string cw_site = "<YourConnectWiseInstance>";
const string cw_companyname = "<YourConnectWiseCompany>";
const string public_key = "<PublicKey>";
const string private_key = "<PrivateKey>";
private static ApiClient GetApiClient()
{
return new ApiClient(cw_app_id, cw_site, cw_companyname)
.SetPublicPrivateKey(public_key, private_key);
}
private static List<Invoice> getInvoices()
{
var client = getApiClient();
var invoicesApi = new InvoiceApi(client);
var response = invoicesApi.GetInvoices();
var invoices = response.GetResult<List<Invoice>>();
foreach (var invoice in invoices)
{
Console.WriteLine(invoice.invoiceNumber);
}
return invoices;
}
Assuming you don't already have them or know what each part is:
On the following page, right hand side, there's a link to download the sample code.
https://developer.connectwise.com/Manage/SDK
Upvotes: 2
Reputation: 21
You can use the tool SoapUI (enter link description here). This tool helps you to test all different WEB Interfaces.
Upvotes: 1