Integrating With a 3rd party Ecommerce Platform

Days are gone when people were selling products only in their stores and days are gone when taking one's business to online was considered as being not affordable and fabulous. Now every business owner can setup an online store and run it. Apart from self hosted platforms like Woocommerce and Magento, there are third-party hosted solutions too with Shopify and Bigcommerce taking the leading role.

You can setup a store online and use third-party delivery services like UPS, Fedex or DHL but what if we want to deliver products on our own? - here Route4Me comes in offering the most advanced software for routing. Route4Me already has built plugins for the top ecommerce platforms (Woocommerce, Magento, Shopify, Bigcommerce) for instantaneous order to route integration. Are you using another ecommerce platform? it's not a problem -This tutorial is dedicated to explain how simple it is to integrate ecommerce platform to Route4Me.

Our Bigcommerce app


After a successful checkout process ecommerce platform generates an order with all the details about the customer and the product that has been ordered. All of the top hosted ecommerce platforms provide API to retrieve order data and you can extend self hosted platforms with integrated plugins. Once you finish gathering the data you care about, you are ready to send them to Route4Me.

All you need is to use 2 methods from the Route4Me API: Forward Geocoding and Create an Order
Method Endpoint HTTP Method
Forward Geocoding POST
Create an Order POST

Geocoding an order address

The primary intention of sending an order to a routing software is to pin the order address on the map, so we can plan a route to the address and make a successful delivery. Pinning an address on the map requires Geocoding, in other words we want to get latitude and longitude out of the address.

1 <?php
2  namespace Route4Me;
4  $vdir=$_SERVER['DOCUMENT_ROOT'].'/route4me/examples/';
6  require $vdir.'/../vendor/autoload.php';
8  use Route4Me\Route4Me;
9  use Route4Me\Route;
11  // Set the api key in the Route4me class
12  Route4Me::setApiKey('11111111111111111111111111111111');
14  $geocodingParameters=array(
15  'format' => 'xml',
16  'addresses' => 'Los20%Angeles20%International20%Airport,20%CA'
17  );
19  $fGeoCoding = new Geocoding();
21  $fgResult = $fGeoCoding->forwardGeocoding($geocodingParameters);
22 ?>

What we do up there in the code block is that we send an address to Route4Me API providing access to only valid API Key and tell it to return response in the xml format. If everything was alright, you can expect the following response:

1 <?xml version="1.0" encoding="UTF-8" ?>
2  <destinations>
3  <destination
4  destination="20 International Rd, Los Angeles, CA 90045, USA"
5  lat="33.9439897"
6  lng="-118.3815557"
7  type="street_address"
8  confidence="high"
9  original="Los20International20CA"
10  />
11  </destinations>

With this response we are getting valid address, latitude and longitude. And we are on the next step.

Creating an order

Now that we geocoded the order address we can pass it to the "Create an order" method along with other order parameters.

1 <?php
2  namespace Route4Me;
4  $vdir=$_SERVER['DOCUMENT_ROOT'].'/route4me/examples/';
5  require $vdir.'/../vendor/autoload.php';
7  use Route4Me\Route4Me;
8  use Route4Me\Order;
10  // Example refers to creating a new Order.
12  // Set the api key in the Route4me class
13  Route4Me::setApiKey('11111111111111111111111111111111');
14 $orderParameters= Order::fromArray(array(
15  "address_1" => "20 International Rd, Los Angeles, CA 90045, USA",
16  "cached_lat" => 33.9439897,
17  "cached_lng" => -118.3815557,
18  "address_alias" => "Order from my store",
19  "address_city" => "Los Angeles",
20  "EXT_FIELD_first_name" => "John",
21  "EXT_FIELD_last_name" => "Doe",
22  "EXT_FIELD_email" => "[email protected]",
23  "EXT_FIELD_phone" => "380380380380",
24  "EXT_FIELD_custom_data" => array(
25  0 =>
26  array(
27  'order_id' => '10',
28  'customer_message' => 'A sample message',
29  )
30  )
31  ));
33  $order = new Order();
35  $response = $order->addOrder($orderParameters);
37  Route4Me::simplePrint($response);
38 ?>
Exported order on Route4Me

Scheduling an Order

When sending an order, you can schedule it to a specific date. To achieve this add following parameter to the order parameters array:

1 "day_scheduled_for_YYMMDD" => "2016-10-05"

With Route4Me you are able to group orders by date. There is a built in calendar which displays days orders are scheduled for.

Scheduled events calendar on Route4Me

Date filter is there on the Orders screen too enabling to display orders for a specific date and to plan a route with them.

Parameters in Custom Data

Not all order parameters can be set as primary parameters when sent to Route4Me. But the good thing is that we can export anything under custom data. For example with our Shopify app under custom data are ending up such parameters as order origin, shipping address, customer provided note, each product attached to an order...

Custom order data


With this tutorial coming to the end, you learned so far how to integrate Route4Me with a 3rd party ecommerce platform. Now using this knowledge you can ditch those shipping service providers, synchronize your online store to the routing software and make a successful delivery.

Useful links: