Search code examples
apitomtom

How to correctly POST requests to TOMTOM's trafficstats API?


I'm trying to get the TOMTOM trafficstats api working and not getting the response I expected. I'm using Postman to generate a POST request to https://{{baseURL}}/traffic/trafficstats/routeanalysis/{{versionNumber}}?key={{apiKey}}

I've set the versionNumber =1 and the key='my TOMTOM access key'. The documentation says that the baseURL should be 'api.tomtom.com' , but I get a "developer inactive" response when doing so. However, if I use baseURL='move.tomtom.com', I get an html response.

I'm sending the following body trying to get historical traffic data on a street in San Francsico:

{
    "jobName":"Test job",
    "distanceUnit":"MILES",
    "routes":[
        {
            "name":"The Embarcadero",
            "start":{
                "latitude":37.794672,
                "longitude":-122.393938
            },
            "via":[
                {
                    "latitude":37.783319,
                    "longitude":-122.388037
                    }
            ],
            "end":{
                "latitude":37.775170,
                "longitude":-122.395783
            },
            "fullTraversal":false,
            "zoneId":"UTC",
            "probeSource":"ALL"
        }
    ],
    "dateRanges":[
        {
            "name":"First day of November",
            "from":"2010-11-01",
            "to":"2010-11-01"
        }
    ],
    "timeSets":[
        {
            "name":"Monday morning hour",
            "timeGroups":[
                {
                    "times":[
                        "7:00-8:00"
                    ]
                }
            ]
        }
    ]
}

The 'Content-Type' of my request header is set to 'application/json'.

I get the following html response. I don't see the expected json data in the body of the html. Any ideas on what I'm doing incorrectly?

 <!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
        <title>TomTom Move</title>
        <base href="/" />
        <link rel="shortcut icon" href="/favicon.png">
        <link href="/css/styles.1337aa094afbb0bd778a.css" rel="stylesheet">
        <link rel="preload" href="/js/styles.7c8029e7a8f45b1dd768.js" as="script">
        <link rel="preload" href="/js/main.2d6a744cf686a687271d.js" as="script">
        <link rel="preload" href="/js/vendors~main.0c1946201ec04090e7a7.js" as="script">
        <link rel="prefetch" href="/js/styles.7c8029e7a8f45b1dd768.js">
        <link rel="prefetch" href="/js/main.2d6a744cf686a687271d.js">
        <link rel="prefetch" href="/js/vendors~main.0c1946201ec04090e7a7.js">
    </head>
    <body>
        <div id="app"></div>
        <!-- Tealium script -->
        <script type="text/javascript">
        (function (a, b, c, d) {
            a = '//tags.tiqcdn.com/utag/tomtom/move/prod/utag.js';
            b = document; c = 'script'; d = b.createElement(c); d.src = a; d.type = 'text/java' + c; d.async = true;
            a = b.getElementsByTagName(c)[0]; a.parentNode.insertBefore(d, a);
        })();
    </script>
        <script type="text/javascript" src="/js/styles.7c8029e7a8f45b1dd768.js"></script>
        <script type="text/javascript" src="/js/main.2d6a744cf686a687271d.js"></script>
        <script type="text/javascript" src="/js/vendors~main.0c1946201ec04090e7a7.js"></script>
    </body>
</html>

Solution

  • TrafficStats is not a public API. So if you don't have an agreement with TomTom then you don't have an access to this API. For that kind of issues it is better to ask TomTom directly.

    And valid baseUrl for TomTom APIs is api.tomtom.com