I'm trying to test TomTom's API Matrix Routing v2 -> Synchronous Matrix (documentation here) with Python's requests.
Here is my code, using their example from the documentation:
import requests
apiKey = 'add_api_key_here'
apiURL = f'https://api.tomtom.com/routing/matrix/2?key={apiKey}'
post_params = {
"origins": [
{
"point": {"latitude": 36.98844, "longitude": -121.97482}
}
],
"destinations": [
{
"point": {"latitude": 34.13007, "longitude": -118.228610}
}
],
"options": {
"traffic": "historical",
"travelMode": "truck",
"vehicleCommercial": True
}
}
headers = {'Content-Type' : 'application/json' }
resp = requests.post(apiURL, data=post_params, headers=headers)
Why am I getting the Response [400] error, saying:
{"detailedError":{"code":"BAD_REQUEST","message":"Bad Request","details":[{"code":"MALFORMED_BODY","message":"Could not parse matrix request","target":"postBody"}]}}
There is surely something I'm missing, I simply cannot see it. :(