Using Custom Data to Trigger Workflows On Mobile Devices

Custom triggers can be assigned to each stop, so that custom workflows can be triggered on a user's mobile device.

Description

You may want to "Add Note" screen automatically opens on the driver's device whenever the driver enters the geofence area of a specific address. That may be convenient for the driver, because he/she doesn't need to find the current address manually. That is also convenient for the manager, because he/she may be confident that the driver adds a note at each destination.

To enable this feature, you have to add the field custom_trigger_open_notes_dialog to the custom data fields of an "address" object and set this field to true.

Solution

Optimization Parameters and addresses

Let us choose a Single Driver Round Trip option for this use case. Here are the parameters for an optimization problem:

ParameterTypeDescriptionHTTP method
api_keystringAPI KEY of the userGET
redirectintegerif equal to 1, will be redirected, if 0 - notGET
addressesarrayValid JSON array of Address objects. Click here to see the JSON SchemaPOST
parametersRoute ParametersValid JSON string of RouteParameters object. Click here to see the JSON SchemaPOST

You can see the addresses on the map as:

Create an Optimization

You can create new optimization for this use case example. From the cUrl example bellow you can see that:

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 Driver Round Trip
3 
4 ::See video tutorial here: http://support.route4me.com/route-planning-help.php?id=manual0:tutorial2:chapter1:subchapter1
5 
6 SET URL=https://www.route4me.com/api.v4/optimization_problem.php
7 SET apikey=11111111111111111111111111111111
8 
9 ECHO ON
10 
11 curl -o file1.txt -g -X POST -k -d "@single_driver_round_trip_data.json" "%URL%?api_key=%apikey%"
12 
13 timeout /t 30

You can expect an Optimization problem (see link), which generated a route 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 @ECHO OFF
2 SET url=https://www.route4me.com/api.v4/optimization_problem.php
3 SET apikey=11111111111111111111111111111111
4 SET optprobid=73ADD7C234F0DC67B5CC5CB71DAC4E6F
5 
6 ECHO ON
7 curl -o file1.txt -g -X GET -k "%URL%?api_key=%apikey%&optimization_problem_id=%optprobid%"
8 
9 timeout /t 30

See sample RESPONSE JSON data here

The system will send a RESPONSE with an array of the addresses, which belongs to one round-trip route.

Details of the Optimized Route

You can get more details of this 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 SET url=https://www.route4me.com/api.v4/route.php
3 SET apikey=11111111111111111111111111111111
4 SET routeid=D456A17625782787E85FEFA06F206DAC
5 SET rpo=Points
6 
7 ECHO ON
8 
9 curl -o file1.txt -g -k -X GET "%url%?route_id=%routeid%&api_key=%apikey%&route_path_output=%rpo%"
10 
11 timeout /t 30

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 generated round trip route as:

Add Custom Field to the Custom Data of a Destination

As described above, there is important custom field for this use case: custom_trigger_open_notes_dialog. It is necessary to add this field to a custom data and then set it to true. Let us add it to the destination selected on the last map 1659 Hibbard Dr, Stow, OH 44224 with route_destination_id=187504358.

HTTP Parameters (see JSON schema here)

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
route_id string Route ID GET
route_destination_id intenger Route destination ID GET
custom_fields array Array of custom fields with string values POST


From the cUrl example bellow you can see that:

1 @ECHO OFF
2 SET url=https://www.route4me.com/api.v4/address.php
3 
4 :: You should insert real test data and your API key for accurate testing
5 
6 SET apikey=11111111111111111111111111111111
7 SET routeid=D456A17625782787E85FEFA06F206DAC
8 SET routedestinationid=187504358
9 
10 ECHO ON
11 
12 curl -o file1.txt -g -k -X PUT -H "Content-Type: application/json" -d "@update_route_destination_custom_data.json" "%url%?api_key=%apikey%&route_id=%routeid%&route_destination_id=%routedestinationid%"
13 
14 timeout /t 30

See sample response data (see here).

Pay attention to the parameter custom_fields:

"custom_fields": {
"custom_trigger_open_notes_dialog": "1"
}

Now when driver enters the geofence area of the destination 1659 Hibbard Dr, Stow, OH 44224, the "Add Note" screen pops up automatically on the driver's phone and the driver will not be able to close that screen until the note is added.