Example Integration
Note: This example uses the Json.NET library from https://www.newtonsoft.com/json
using System.Text;
using System.Net;
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace TestClientConsoleApp
{
class Program
{
static void Main(string[] args)
{
// Set the web service API address here
const string URL = "http://localhost:56411/Service/wsPDMApi.svc";
// Set the API key here
const string API_KEY = "A54C18709701456E904F3FE78712E73E";
// Set some values here for test purposes
const int COMPANY_ID = 9001;
const int CUSTOMER_ID = 1408;
// Get the session token and store for ongoing calls to the web service API
string SessionToken = GetSessionToken(URL, API_KEY, COMPANY_ID, true);
// GetSessionToken
string getSessionTokenResponse = GetSessionToken(URL, API_KEY, COMPANY_ID);
// GetCustomer
string getCustomerResponse = GetCustomer(URL, SessionToken, COMPANY_ID, CUSTOMER_ID, string.Empty);
// CreateCustomer
string createCustomerResponse = CreateCustomer(URL, SessionToken, COMPANY_ID);
// ModifyCustomer
string modifyCustomerResponse = ModifyCustomer(URL, SessionToken, COMPANY_ID, CUSTOMER_ID);
// CreateDelivery
string createDeliveryResponse = CreateDelivery(URL, SessionToken, COMPANY_ID, CUSTOMER_ID);
// CreateCollection
string createCollectionResponse = CreateCollection(URL, SessionToken, COMPANY_ID, CUSTOMER_ID);
}
public static string GetSessionToken(string _url, string _apiKey, int _companyId, bool _tokenStringOnly = false)
{
// Create the request object
object request = new
{
key = _apiKey,
company_id = _companyId
};
JObject response = WebServiceRequest(_url, "GetSessionToken", request);
if (_tokenStringOnly)
{
JToken session = response.GetValue("session");
JToken sessionToken = session.SelectToken("session_token");
return sessionToken.ToString();
}
System.Diagnostics.Debug.Print("Response: " + response.ToString());
return response.ToString();
}
public static string GetCustomer(string _url, string _sessionToken, int _companyId, int _customerId, string _externalRef)
{
// Create the request object
object request = new
{
company_id = _companyId,
session_token = _sessionToken,
customer_id = _customerId,
external_customer_ref = _externalRef
};
JObject response = WebServiceRequest(_url, "GetCustomer", request);
System.Diagnostics.Debug.Print("Response: " + response.ToString());
return response.ToString();
}
public static string CreateCustomer(string _url, string _sessionToken, int _companyId)
{
// Create the request object
object customer = CreateCustomerObject(CreateAddressObject());
object request = new
{
company_id = _companyId,
session_token = _sessionToken,
customer = customer
};
JObject response = WebServiceRequest(_url, "CreateCustomer", request);
System.Diagnostics.Debug.Print("Response: " + response.ToString());
return response.ToString();
}
public static string ModifyCustomer(string _url, string _sessionToken, int _companyId, int _customerId)
{
// Create the request object
object customer = ModifyCustomerObject(_customerId, CreateAddressObject());
object request = new
{
company_id = _companyId,
session_token = _sessionToken,
customer = customer
};
JObject response = WebServiceRequest(_url, "ModifyCustomer", request);
System.Diagnostics.Debug.Print("Response: " + response.ToString());
return response.ToString();
}
public static string CreateDelivery(string _url, string _sessionToken, int _companyId, int _customerId)
{
List