I am creating a integration to a 3rd party logistics company utilizing their REST calls and I am struggling trying to create the body. I followed what you shown above and was wondering if you could give tis a quick review and let me know what I may be doing wrong. I appreciate any feedback.
Another thing you can do is create a class in c# that you can load an epicor data table or result to so that you have strongly defined fields/objects in the class. Then you can serialize the class into a json object using newtonsoft.
I’ve found it makes checking for null data and invalid casts down the line a lot cleaner.
public class SharedLtLBookingResponseObject
{
public string id { get; set; }
public DateTime createdDate { get; set; }
public bool archived { get; set; }
public string direction { get; set; }
public DateTime pickupDate { get; set; }
public string status { get; set; }
public Billto billTo { get; set; }
public string[] accessorials { get; set; }
public Origin origin { get; set; }
public Destination destination { get; set; }
public Tracking tracking { get; set; }
public File[] files { get; set; }
public Invoice invoice { get; set; }
public string[] shareShipmentEmails { get; set; }
public string quotedBy { get; set; }
public string bookedBy { get; set; }
public string bolNum { get; set; }
public string paymentTerms { get; set; }
public Item[] items { get; set; }
public Rate rate { get; set; }
public Dispatch dispatch { get; set; }
}
public class Billto
{
public string company { get; set; }
public string address { get; set; }
public string address2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postalCode { get; set; }
public string country { get; set; }
public string contactName { get; set; }
public string contactEmail { get; set; }
public string contactPhone { get; set; }
}
public class Origin
{
public string company { get; set; }
public string address { get; set; }
public string address2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postalCode { get; set; }
public string country { get; set; }
public string shipType { get; set; }
public string contactName { get; set; }
public string contactPhone { get; set; }
public string contactEmail { get; set; }
public string referenceNumber { get; set; }
public string instructions { get; set; }
public string dockHoursOpen { get; set; }
public string dockHoursClose { get; set; }
}
public class Destination
{
public string company { get; set; }
public string address { get; set; }
public string address2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postalCode { get; set; }
public string country { get; set; }
public string shipType { get; set; }
public string contactName { get; set; }
public string contactPhone { get; set; }
public string contactEmail { get; set; }
public string referenceNumber { get; set; }
public string instructions { get; set; }
public string dockHoursOpen { get; set; }
public string dockHoursClose { get; set; }
}
public class Tracking
{
public string status { get; set; }
public string summary { get; set; }
public DateTime lastUpdatedDate { get; set; }
public DateTime pickupDateActual { get; set; }
public DateTime deliveryDateEstimate { get; set; }
public DateTime deliveryDateActual { get; set; }
public History[] history { get; set; }
}
public class History
{
public string status { get; set; }
public string summary { get; set; }
public DateTime createdDate { get; set; }
}
public class Invoice
{
public DateTime createdDate { get; set; }
public double invoiceAmount { get; set; }
public string invoiceNumber { get; set; }
public double disputedAmount { get; set; }
public Payment[] payments { get; set; }
}
public class Payment
{
public double amount { get; set; }
public bool remitted { get; set; }
}
public class Rate
{
public double total { get; set; }
public int days { get; set; }
public string serviceType { get; set; }
public string serviceOption { get; set; }
public string serviceDescription { get; set; }
public string carrierId { get; set; }
public string carrier { get; set; }
public string carrierCode { get; set; }
public int time { get; set; }
public bool rural { get; set; }
public Charge[] charges { get; set; }
public bool interline { get; set; }
public bool daysPlus { get; set; }
public string mode { get; set; }
public string paymentTerms { get; set; }
public string provider { get; set; }
public string providerCode { get; set; }
public DateTime createdDate { get; set; }
public string quoteNum { get; set; }
}
public class Charge
{
public string name { get; set; }
public double amount { get; set; }
public string providerDetail { get; set; }
public string code { get; set; }
}
public class Dispatch
{
public string carrierId { get; set; }
public string carrier { get; set; }
public string carrierCode { get; set; }
public bool schedulePickup { get; set; }
public string bolStatus { get; set; }
public string pickupNum { get; set; }
public string proNum { get; set; }
}
public class File
{
public string type { get; set; }
public string subtype { get; set; }
public DateTime uploadDate { get; set; }
public string url { get; set; }
}
public class Item
{
public string description { get; set; }
public int weight { get; set; }
public int freightClass { get; set; }
public int length { get; set; }
public int width { get; set; }
public int height { get; set; }
public string package { get; set; }
public int pieces { get; set; }
public string nmfc { get; set; }
public bool hazardous { get; set; }
public Hazard hazard { get; set; }
public int saidToContain { get; set; }
public string saidToContainPackagingType { get; set; }
public bool stackable { get; set; }
}
public class Hazard
{
public string hazmatId { get; set; }
public string hazardClass { get; set; }
public string hazardSubClass1 { get; set; }
public string hazardSubClass2 { get; set; }
public string packingGroup { get; set; }
public string specialPermit { get; set; }
}
public class FreightViewResponseErrorMessage
{
public string error { get; set; }
public string errorType { get; set; }
public string message { get; set; }
}
Here’s the desrialization:
using (var reader = new StreamReader(response.GetResponseStream()))
{
/*Here we are converting the booking response into a class so that we can access the properties of it like:
the booking ID, the proNum, and the URL for any labels. We are also checking to make sure the result was a success.*/
SharedLtLBookingResponseObject BookingResponse = new SharedLtLBookingResponseObject();
var jsonResult = reader.ReadToEnd();
BookingResponse = JsonConvert.DeserializeObject<SharedLtLBookingResponseObject>(jsonResult);
And Scott if you have an example of the JSON you can copy it into a C# visual studio project and say, “create as class,” and then you’ll have somethign you can copy and paste into your form customization if you are doing it in classic forms.
But if you’re doing it in BPM or function for kinetic then I think there’s no luck using classes yet, right @klincecum ?
Like Kevin says, not directly. IF one follows some decoupling practices, there would be a facade pattern between the 3rd party and Kinetic. In that endpoint, you’d have the full freedom to create a validation class - which IS a good idea. This level of abstraction could also help hide API-Keys from the client to provide a more secure integration - a backend for front end. It would also place a buffer between changes in the APIs of each party.