Error while using API on vroom

vehicle_start = [-34.9658392782709, -7.1380845]
coordinates= [[-34.9658392782709, -7.1380845], [-34.9071513370733, -7.26357182671599], [-35.4899649848849, -6.852715], [-34.8889419445777, -8.06276248305241]]

body = {
    "jobs": [
        {"id": 1, "service": 300, "amount": [1], "location": [-34.9658392782709, -7.1380845]},
        {"id": 2, "service": 300, "amount": [1], "location": [-34.9071513370733, -7.26357182671599]},
        {"id": 3, "service": 300, "amount": [1], "location": [-35.4899649848849, -6.852715]},
        {"id": 4, "service": 300, "amount": [1], "location": [-34.8889419445777, -8.06276248305241]}
    ],
    "vehicles": [
        {
            "id": 1,
            "profile": "driving-car",
            "start": [-34.9658392782709, -7.1380845],
            "capacity": [2000]
        }
    ],
    "options": {"g": 'true'}
}

headers = {
    'Accept': 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8',
    'Content-Type': 'application/json; charset=utf-8'
}

response = requests.post('vroom_url', json=body, headers=headers)
print(response.json())

this code returns a succes response, but the one bellow returns HTTP error 404

coordinates = [[-34.9658392782709, -7.1380845], [-34.9071513370733, -7.26357182671599], 
               [-35.4899649848849, -6.852715], [-34.8889419445777, -8.06276248305241]]
jobs, vehicles = list(), list()
vehicle_start = [-34.9658392782709, -7.1380845]
for idx, coord in enumerate(coordinates):
  jobs.append(optimization.Job(id=idx, location=coord,amount=[1]))

cap = 5

vehicles = [
    optimization.Vehicle(id=0, profile='driving-car', start=vehicle_start, capacity=[cap]),
]
try:
    api = Client(base_url='same_vroom_url')
    result = api.optimization(jobs=jobs, vehicles=vehicles, geometry=True)
except Exception as e:
    print(e)
    
print(result.json())

i would like to know if im doing anything wrong with the API

Hey,

when using openrouteservice.Client.optimization(), you are requesting <base_url>/optimization which probably does not exist for your VROOM url.

You can either look at openrouteservice.Client.request() or go with your requests-based approach.

Best regards

is there any way i can change my vroom/ors setup so i can use the .optimization() funcion or even the .directions(optimization_waypoint=True), it would be way more practical to implement on my current application

Hey,

assuming you are running vroom-docker, you can add /optimization to the baseurl in your VROOM config.yml.

Note, that you’ll have to add the port of your VROOM instance (by default 3000) to the base_url of your Client.

Best regards

oh, ok i see, thanks. A more specific question now is there a way where i can make dropoffs associated with pick ups, on the sense of, a dropoff is only allowed after the vehicle has been to the pickup job associated ? If its too especific to be answered i would also appreciate a link to tutorials/ more complex examples, the ones i found on vroom’s github are quite confusing

Hi,

I thing you must check the following-

  • Ensure that optimization.Job and optimization.Vehicle are properly defined and compatible with the API.
  • Verify that the Client library is correctly initialized and that the base URL is formatted properly (e.g., including the /api/ part if needed).
  • Check if the 404 error is specific to missing endpoint details in the second method or incorrect URL handling in the wrapper.

Thanks :slightly_smiling_face: