• Home
  • Contacts
  • On The Go
  • Track
  • Settings
  • Search

Transport API

The Transport API allows users to get an estimated cost break down exclusive of GST for moving freight from one location to another.

All methods utilise a RESTful approach; supporting both XML and JSON formats. 

Available Methods

Security

An API key is required for all requests. Please register to request your API key.

API Terms of Use

By registering for and/or accessing any API found on this developer website, you understand and have agreed to our API Terms of Use.

Click here to read our API Terms of Use.

Model Drop in DLL

Mainfreight provides a .NET compatible library with model for all the entities that can be used to make it easier for developers to communicate with the Mainfreight APIs.

Service consumer Drop in DLL

Mainfreight also provides a .NET compatible library which provides wrapping methods to easily consume the Mainfreight Transport Rating API.

You can find a copy of these drop in dlls here.

Please note, Mainfreight.Api.Transport.Client.dll requires Mainfreight.Api.Transport.Model.dll and Mainfreight.Api.Common.Client.dll.

Drop in DLL usage example

References Example

To list all available anonymous notifications for a particular document you have to post a json similar to this (notice that no session secret is used):

  • C#
< > grab code
try
{
    TransportClient client = new TransportClient("YOUR_API_KEY");
    
    Model.Customer.Rate.In.Rate request = new Model.Customer.Rate.In.Rate()
    {
        Account = new Model.Customer.Rate.In.Account()
        {
            Code = "YOUR_ACCOUNT_CODE"
        },
        ServiceLevel = new Model.Customer.Rate.In.ServiceLevel()
        {
            Code = "YOUR_SERVICE_CODE"
        },
        Origin = new Model.Customer.Rate.In.Origin()
        {
            FreightRequiredDateTime = DateTime.Now,
            FreightRequiredDateTimeZone = "New Zealand Standard Time",
            Address = new Model.Customer.Rate.In.Address()
            {
                Suburb = "Grey Lynn",
                City = "Auckland",
                PostCode = "1011",
                CountryCode = "NZ"
            }
        },
        Destination = new Model.Customer.Rate.In.Destination()
        {
            Address = new Model.Customer.Rate.In.Address()
            {
                Suburb = "Mount Cook",
                City = "Wellington",
                PostCode = "6011",
                CountryCode = "NZ"
            },
        },
        FreightDetails = new List<Model.Customer.Rate.In.FreightDetail>()
        {
            new Model.Customer.Rate.In.FreightDetail()
            {
                Units = 1,
                PackTypeCode = "PLT",
                Height = 1.23M,
                Length = 1.45M,
                Width = 1.6M,
                Weight = 120,
                Volume = 2.86M
            },
            new Model.Customer.Rate.In.FreightDetail()
            {
                Units = 2,
                PackTypeCode = "BAG",
                Height = 2.23M,
                Length = 1.45M,
                Width = 1.6M,
                Weight = 60,
                Volume = 10.35M
            }
        }
    };
    Model.Customer.Rate.Out.Rate response = client.CustomerRate(request, "NZ");

    if (response.Charges > 0)
    {
        for (var i = 0; i < response.Charges.Count; i++)
        {
            Console.WriteLine(
                string.Format("Name = {0}, Value = {1} \r\n",
                    response.Charges[i].Name,
                    response.Charges[i].Value
                )
            );
        }
    }
    else
    {
        Console.WriteLine("There is no matching rate.");
    }
}
catch (TransportClientException scx)
{
    if (scx.Error != null)
    {
        Console.WriteLine(
            string.Format("Code = {0}\r\nResponseCode = {1} \r\nMessage: \r\n{2}\r\nTarget: \r\n{3}",
                scx.Error.Code,
                scx.Error.ResponseCode,
                scx.Error.Message,
                scx.Error.Target
            )
        );
        if (scx.Error.Details != null)
        {
            foreach (Detail error in scx.Error.Details)
            {
                Console.WriteLine(
                    string.Format("INNER ERROR: Code = {0} \r\nMessage: \r\n{1}\r\nTarget: \r\n{2}",
                        error.Code,
                        error.Message,
                        error.Target
                    )
                );
            }
        }
    }

}
catch (Exception ex)
{
    Console.WriteLine(string.Format("Message = {0}", ex.Message));
}

Console.WriteLine("Request completed...");
Console.ReadKey();

 

Access

To access to Mainfreight APIs, you have to Register

NOTE: Content in the panels below this point are not visible on the site unless used by other features e.g. gadgets, OB&E, etc.