curl -X POST "https://trackservice.trackroad.com/rest/dispatch" \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_TRACKSERVICEKEY" \
-d '{
"RoutingService": 0,
"DistanceUnit": 0,
"RouteOptimize": 0,
"DispatchMode": 0,
"Vehicles": [
{
"Name": "Truck 1",
"StartLocation": { "LatLong": { "Latitude": 37.7946, "Longitude": -122.3950 }, "LocationType": 1 },
"FinishLocation": { "LatLong": { "Latitude": 37.7946, "Longitude": -122.3950 }, "LocationType": 2 }
}
],
"Locations": [
{ "Name": "Stop A", "LatLong": { "Latitude": 37.7897, "Longitude": -122.4011 }, "LocationType": 0 },
{ "Name": "Stop B", "LatLong": { "Latitude": 37.7810, "Longitude": -122.4110 }, "LocationType": 0 }
]
}'
using System.Net.Http;
using System.Text;
var url = "https://trackservice.trackroad.com/rest/dispatch";
using var http = new HttpClient();
http.DefaultRequestHeaders.Add("X-API-Key", "YOUR_TRACKSERVICEKEY");
var json = @"{
""RoutingService"": 0,
""DistanceUnit"": 0,
""RouteOptimize"": 0,
""DispatchMode"": 0,
""Vehicles"": [
{
""Name"": ""Truck 1"",
""StartLocation"": { ""LatLong"": { ""Latitude"": 37.7946, ""Longitude"": -122.3950 }, ""LocationType"": 1 },
""FinishLocation"": { ""LatLong"": { ""Latitude"": 37.7946, ""Longitude"": -122.3950 }, ""LocationType"": 2 }
}
],
""Locations"": [
{ ""Name"": ""Stop A"", ""LatLong"": { ""Latitude"": 37.7897, ""Longitude"": -122.4011 }, ""LocationType"": 0 },
{ ""Name"": ""Stop B"", ""LatLong"": { ""Latitude"": 37.7810, ""Longitude"": -122.4110 }, ""LocationType"": 0 }
]
}";
using var content = new StringContent(json, Encoding.UTF8, "application/json");
var resp = await http.PostAsync(url, content);
Console.WriteLine(await resp.Content.ReadAsStringAsync());
const url = "https://trackservice.trackroad.com/rest/dispatch";
const payload = {
RoutingService: 0,
DistanceUnit: 0,
RouteOptimize: 0,
DispatchMode: 0,
Vehicles: [
{
Name: "Truck 1",
StartLocation: { LatLong: { Latitude: 37.7946, Longitude: -122.3950 }, LocationType: 1 },
FinishLocation: { LatLong: { Latitude: 37.7946, Longitude: -122.3950 }, LocationType: 2 }
}
],
Locations: [
{ Name: "Stop A", LatLong: { Latitude: 37.7897, Longitude: -122.4011 }, LocationType: 0 },
{ Name: "Stop B", LatLong: { Latitude: 37.7810, Longitude: -122.4110 }, LocationType: 0 }
]
};
const res = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": "YOUR_TRACKSERVICEKEY"
},
body: JSON.stringify(payload)
});
console.log(await res.text());
import okhttp3.*;
public class Main {
public static void main(String[] args) throws Exception {
OkHttpClient client = new OkHttpClient();
String json = "{"
+ "\"RoutingService\":0,"
+ "\"DistanceUnit\":0,"
+ "\"RouteOptimize\":0,"
+ "\"DispatchMode\":0,"
+ "\"Vehicles\":[{"
+ "\"Name\":\"Truck 1\","
+ "\"StartLocation\":{\"LatLong\":{\"Latitude\":37.7946,\"Longitude\":-122.3950},\"LocationType\":1},"
+ "\"FinishLocation\":{\"LatLong\":{\"Latitude\":37.7946,\"Longitude\":-122.3950},\"LocationType\":2}"
+ "}],"
+ "\"Locations\":[{"
+ "\"Name\":\"Stop A\","
+ "\"LatLong\":{\"Latitude\":37.7897,\"Longitude\":-122.4011},"
+ "\"LocationType\":0"
+ "},{"
+ "\"Name\":\"Stop B\","
+ "\"LatLong\":{\"Latitude\":37.7810,\"Longitude\":-122.4110},"
+ "\"LocationType\":0"
+ "}]"
+ "}";
RequestBody body = RequestBody.create(json, MediaType.parse("application/json"));
Request request = new Request.Builder()
.url("https://trackservice.trackroad.com/rest/dispatch")
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("X-API-Key", "YOUR_TRACKSERVICEKEY")
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}
}
}
import requests
url = "https://trackservice.trackroad.com/rest/dispatch"
headers = {
"Content-Type": "application/json",
"X-API-Key": "YOUR_TRACKSERVICEKEY"
}
payload = {
"RoutingService": 0,
"DistanceUnit": 0,
"RouteOptimize": 0,
"DispatchMode": 0,
"Vehicles": [
{
"Name": "Truck 1",
"StartLocation": { "LatLong": { "Latitude": 37.7946, "Longitude": -122.3950 }, "LocationType": 1 },
"FinishLocation": { "LatLong": { "Latitude": 37.7946, "Longitude": -122.3950 }, "LocationType": 2 }
}
],
"Locations": [
{ "Name": "Stop A", "LatLong": { "Latitude": 37.7897, "Longitude": -122.4011 }, "LocationType": 0 },
{ "Name": "Stop B", "LatLong": { "Latitude": 37.7810, "Longitude": -122.4110 }, "LocationType": 0 }
]
}
r = requests.post(url, headers=headers, json=payload)
print(r.text)
<?php
$url = "https://trackservice.trackroad.com/rest/dispatch";
$payload = json_encode([
"RoutingService" => 0,
"DistanceUnit" => 0,
"RouteOptimize" => 0,
"DispatchMode" => 0,
"Vehicles" => [[
"Name" => "Truck 1",
"StartLocation" => [ "LatLong" => [ "Latitude" => 37.7946, "Longitude" => -122.3950 ], "LocationType" => 1 ],
"FinishLocation" => [ "LatLong" => [ "Latitude" => 37.7946, "Longitude" => -122.3950 ], "LocationType" => 2 ]
]],
"Locations" => [
[ "Name" => "Stop A", "LatLong" => [ "Latitude" => 37.7897, "Longitude" => -122.4011 ], "LocationType" => 0 ],
[ "Name" => "Stop B", "LatLong" => [ "Latitude" => 37.7810, "Longitude" => -122.4110 ], "LocationType" => 0 ]
]
]);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: YOUR_TRACKSERVICEKEY"
],
CURLOPT_POSTFIELDS => $payload
]);
echo curl_exec($ch);
curl_close($ch);
require "net/http"
require "json"
uri = URI("https://trackservice.trackroad.com/rest/dispatch")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
payload = {
RoutingService: 0,
DistanceUnit: 0,
RouteOptimize: 0,
DispatchMode: 0,
Vehicles: [
{
Name: "Truck 1",
StartLocation: { LatLong: { Latitude: 37.7946, Longitude: -122.3950 }, LocationType: 1 },
FinishLocation: { LatLong: { Latitude: 37.7946, Longitude: -122.3950 }, LocationType: 2 }
}
],
Locations: [
{ Name: "Stop A", LatLong: { Latitude: 37.7897, Longitude: -122.4011 }, LocationType: 0 },
{ Name: "Stop B", LatLong: { Latitude: 37.7810, Longitude: -122.4110 }, LocationType: 0 }
]
}
req = Net::HTTP::Post.new(uri)
req["Content-Type"] = "application/json"
req["X-API-Key"] = "YOUR_TRACKSERVICEKEY"
req.body = payload.to_json
res = http.request(req)
puts res.body
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://trackservice.trackroad.com/rest/dispatch"
jsonBody := []byte(`{
"RoutingService": 0,
"DistanceUnit": 0,
"RouteOptimize": 0,
"DispatchMode": 0,
"Vehicles": [
{
"Name": "Truck 1",
"StartLocation": { "LatLong": { "Latitude": 37.7946, "Longitude": -122.3950 }, "LocationType": 1 },
"FinishLocation": { "LatLong": { "Latitude": 37.7946, "Longitude": -122.3950 }, "LocationType": 2 }
}
],
"Locations": [
{ "Name": "Stop A", "LatLong": { "Latitude": 37.7897, "Longitude": -122.4011 }, "LocationType": 0 },
{ "Name": "Stop B", "LatLong": { "Latitude": 37.7810, "Longitude": -122.4110 }, "LocationType": 0 }
]
}`)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonBody))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-API-Key", "YOUR_TRACKSERVICEKEY")
resp, err := http.DefaultClient.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
b, _ := io.ReadAll(resp.Body)
fmt.Println(string(b))
}
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
fun main() {
val url = "https://trackservice.trackroad.com/rest/dispatch"
val json = """
{
"RoutingService": 0,
"DistanceUnit": 0,
"RouteOptimize": 0,
"DispatchMode": 0,
"Vehicles": [
{
"Name": "Truck 1",
"StartLocation": { "LatLong": { "Latitude": 37.7946, "Longitude": -122.3950 }, "LocationType": 1 },
"FinishLocation": { "LatLong": { "Latitude": 37.7946, "Longitude": -122.3950 }, "LocationType": 2 }
}
],
"Locations": [
{ "Name": "Stop A", "LatLong": { "Latitude": 37.7897, "Longitude": -122.4011 }, "LocationType": 0 },
{ "Name": "Stop B", "LatLong": { "Latitude": 37.7810, "Longitude": -122.4110 }, "LocationType": 0 }
]
}
""".trimIndent()
val client = HttpClient.newHttpClient()
val req = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("X-API-Key", "YOUR_TRACKSERVICEKEY")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build()
val resp = client.send(req, HttpResponse.BodyHandlers.ofString())
println(resp.body())
}
#include <stdio.h>
#include <curl/curl.h>
int main(void) {
CURL *curl = curl_easy_init();
if(!curl) return 1;
const char *url = "https://trackservice.trackroad.com/rest/dispatch";
const char *json =
"{"
"\"RoutingService\":0,"
"\"DistanceUnit\":0,"
"\"RouteOptimize\":0,"
"\"DispatchMode\":0,"
"\"Vehicles\":[{"
"\"Name\":\"Truck 1\","
"\"StartLocation\":{\"LatLong\":{\"Latitude\":37.7946,\"Longitude\":-122.3950},\"LocationType\":1},"
"\"FinishLocation\":{\"LatLong\":{\"Latitude\":37.7946,\"Longitude\":-122.3950},\"LocationType\":2}"
"}],"
"\"Locations\":[{"
"\"Name\":\"Stop A\","
"\"LatLong\":{\"Latitude\":37.7897,\"Longitude\":-122.4011},"
"\"LocationType\":0"
"},{"
"\"Name\":\"Stop B\","
"\"LatLong\":{\"Latitude\":37.7810,\"Longitude\":-122.4110},"
"\"LocationType\":0"
"}]"
"}";
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "X-API-Key: YOUR_TRACKSERVICEKEY");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
CURLcode res = curl_easy_perform(curl);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return (res == CURLE_OK) ? 0 : 1;
}
#include <curl/curl.h>
#include <string>
int main() {
CURL* curl = curl_easy_init();
if(!curl) return 1;
std::string url = "https://trackservice.trackroad.com/rest/dispatch";
std::string json =
"{"
"\"RoutingService\":0,"
"\"DistanceUnit\":0,"
"\"RouteOptimize\":0,"
"\"DispatchMode\":0,"
"\"Vehicles\":[{"
"\"Name\":\"Truck 1\","
"\"StartLocation\":{\"LatLong\":{\"Latitude\":37.7946,\"Longitude\":-122.3950},\"LocationType\":1},"
"\"FinishLocation\":{\"LatLong\":{\"Latitude\":37.7946,\"Longitude\":-122.3950},\"LocationType\":2}"
"}],"
"\"Locations\":[{"
"\"Name\":\"Stop A\","
"\"LatLong\":{\"Latitude\":37.7897,\"Longitude\":-122.4011},"
"\"LocationType\":0"
"},{"
"\"Name\":\"Stop B\","
"\"LatLong\":{\"Latitude\":37.7810,\"Longitude\":-122.4110},"
"\"LocationType\":0"
"}]"
"}";
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "X-API-Key: YOUR_TRACKSERVICEKEY");
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json.c_str());
CURLcode res = curl_easy_perform(curl);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return (res == CURLE_OK) ? 0 : 1;
}
#import <Foundation/Foundation.h>
int main() {
@autoreleasepool {
NSURL *url = [NSURL URLWithString:@"https://trackservice.trackroad.com/rest/dispatch"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req setHTTPMethod:@"POST"];
[req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[req setValue:@"YOUR_TRACKSERVICEKEY" forHTTPHeaderField:@"X-API-Key"];
NSDictionary *payload = @{
@"RoutingService": @0,
@"DistanceUnit": @0,
@"RouteOptimize": @0,
@"DispatchMode": @0,
@"Vehicles": @[
@{
@"Name": @"Truck 1",
@"StartLocation": @{@"LatLong": @{@"Latitude": @37.7946, @"Longitude": @-122.3950}, @"LocationType": @1},
@"FinishLocation": @{@"LatLong": @{@"Latitude": @37.7946, @"Longitude": @-122.3950}, @"LocationType": @2}
}
],
@"Locations": @[
@{@"Name": @"Stop A", @"LatLong": @{@"Latitude": @37.7897, @"Longitude": @-122.4011}, @"LocationType": @0},
@{@"Name": @"Stop B", @"LatLong": @{@"Latitude": @37.7810, @"Longitude": @-122.4110}, @"LocationType": @0}
]
};
NSData *body = [NSJSONSerialization dataWithJSONObject:payload options:0 error:nil];
[req setHTTPBody:body];
NSURLSessionDataTask *task =
[[NSURLSession sharedSession] dataTaskWithRequest:req
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) { NSLog(@"%@", error); return; }
NSString *text = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", text);
}];
[task resume];
[[NSRunLoop currentRunLoop] run];
}
return 0;
}
import Foundation
let url = URL(string: "https://trackservice.trackroad.com/rest/dispatch")!
var req = URLRequest(url: url)
req.httpMethod = "POST"
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
req.setValue("YOUR_TRACKSERVICEKEY", forHTTPHeaderField: "X-API-Key")
let payload: [String: Any] = [
"RoutingService": 0,
"DistanceUnit": 0,
"RouteOptimize": 0,
"DispatchMode": 0,
"Vehicles": [
[
"Name": "Truck 1",
"StartLocation": ["LatLong": ["Latitude": 37.7946, "Longitude": -122.3950], "LocationType": 1],
"FinishLocation": ["LatLong": ["Latitude": 37.7946, "Longitude": -122.3950], "LocationType": 2]
]
],
"Locations": [
["Name": "Stop A", "LatLong": ["Latitude": 37.7897, "Longitude": -122.4011], "LocationType": 0],
["Name": "Stop B", "LatLong": ["Latitude": 37.7810, "Longitude": -122.4110], "LocationType": 0]
]
]
req.httpBody = try! JSONSerialization.data(withJSONObject: payload)
let task = URLSession.shared.dataTask(with: req) { data, _, error in
if let error = error { print(error); return }
print(String(data: data ?? Data(), encoding: .utf8) ?? "")
}
task.resume()
RunLoop.main.run()