Creating a New Route Based on Another Route

See files for this Use Case on the GitHub here

Description

Once a route has been created, it can be edited and saved with a different name. Please pay attention that it supersedes the existing edited route rather than being a new route based on the one just edited. You can duplicate an already existing route to create a new version. Routes duplication can be useful when it is necessary to make copies of a route you want to modify and you do not want to distort the existing route.

Solution

Create an Optimization

The cURL example below shows you how to create new optimized routes for this Use Case:

ParameterTypeDescription
api_keystringAPI KEY of the user
input dataPOST dataValid JSON object string. Click here to see the JSON Schema
1 @ECHO OFF
2 :: Single Depot, Multiple Driver, No Time Window
3 
4 ::See video tutorial here: http://support.route4me.com/route-planning-help.php?id=manual0:tutorial2:chapter2:subchapter1
5 
6 SET URL=https://www.route4me.com/api.v4/optimization_problem.php
7 SET apikey=11111111111111111111111111111111
8 SET route_path_output=Points
9 
10 ECHO ON
11 
12 curl -o file1.txt -g -X POST -k -d "@new_route_from-existing_route_data.json" "%URL%?api_key=%apikey%&route_path_output=%route_path_output%"
13 
14 timeout /t 30

You can expect an Optimization Problem (see link), which has generated two routes already.

View the Optimization details

You can get more details from the newly created Optimization Problem.

The endpoint: https://www.route4me.com/api.v4/optimization_problem.php

HTTP Parameters

AttributeTypeDescriptionHTTP
method
api_keystringAPI KEY of the userGET
optimization_problem_idstringOptimization problem IDGET


1 es (7 sloc) 283 Bytes
2 @ECHO OFF
3 
4 SET url=https://www.route4me.com/api.v4/optimization_problem.php
5 SET apikey=11111111111111111111111111111111
6 SET optprobid=DC389C49A9A1AE555336140E189BA104
7 
8 ECHO ON
9 curl -o file1.txt -g -X GET -k "%URL%?api_key=%apikey%&optimization_problem_id=%optprobid%"
10 
11 timeout /t 30

See sample RESPONSE JSON data here

The system will send a RESPONSE wiht an array of addresses, which belong to two routes - a small one and a big one.

Details of the Optimized Route

The endpoint: https://www.route4me.com/api.v4/route.php

HTTP Parameters

AttributeTypeDescriptionHTTP
method
api_keystringAPI KEY of the userGET
route_idstringRoute IDGET
route_path_outputstringIf equal to 'Poitns', you'll get an array of the path points to next addressGET


1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/route.php
4 SET apikey=11111111111111111111111111111111
5 SET routeid=32587465EAA62D7412F9C37EF786C0AE
6 SET rpo=Points
7 
8 ECHO ON
9 
10 curl -o file1.txt -g -k -X GET "%url%?route_id=%routeid%&api_key=%apikey%&route_path_output=%rpo%"
11 
12 timeout

See sample RESPONSE JSON data here

Note
In the RESPONSE you can see the array of the fields path_to_next. Those will be used to draw routes on a map, exactly as they generated by Route4Me API..

You can draw the generated small route as:

You can do same for big route with route_id=92BCD9B1935331026B0A09E56B1E34C0

See sample RESPONSE JSON data here

The big route on a map:

Duplicate a Route

Let's duplicate the small route with route_id=32587465EAA62D7412F9C37EF786C0AE.

Note
Accepts a unique route_id which exists in the Route4Me database and duplicates the route. The duplicated route has all the same metadata and account ownership information as the original route. However, route notes and visited status flags are not copied into the new route. The name of the new route is automatically appended with the string “ (Duplicate)” to indicate that the route is a duplicate route. There is currently no special designation inside the database to indicate that a route originated from another route.

The endpoint: https://www.route4me.com/actions/duplicate_route.php

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
route_id string Route ID GET


1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/actions/duplicate_route.php
4 SET apikey=11111111111111111111111111111111
5 SET routeid=32587465EAA62D7412F9C37EF786C0AE
6 
7 ECHO ON
8 curl -o file1.txt -g -k -X GET "%url%?api_key=%apikey%&route_id=%routeid%&to=none"
9 
10 timeout /t 30

You can expect this API response:

{
"optimization_problem_id":"4EF692E8FC5CD08B6E32DF19E50F3C1F",
"success":true
}

As you can notice, duplicating of the route created new optimization problem with small route and addresses.

Other Method of a Route Duplicating

There is other "shadow" method of a route duplicating. Let's duplicatie the big route with route_id=92BCD9B1935331026B0A09E56B1E34C0.

The endpoint: https://www.route4me.com/api.v4/route.php

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
route_id string Route ID GET
POST data route Valid JSON string of a Route object POST


See sample INPUT JSON data here

1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/route.php
4 SET apikey=11111111111111111111111111111111
5 SET routeid=92BCD9B1935331026B0A09E56B1E34C0
6 
7 ECHO ON
8 
9 curl -o file1.txt -g -k -X PUT -H "Content-Type: application/json" -d "@set_custom_id_data.json" "%url%?api_key=%apikey%&route_id=%routeid%"
10 
11 timeout /t 30

See sample RESPONSE JSON data here

You can apply the above described procedure of getting an optimization problem (see link) and see that now there are three routes associated with the initial optimization problem: small one and two big ones. Big routes differ from each other by only the route IDs and route names.