I was about to use the Routing API of PTV Developer in Visual Studio C#. Steps are:
- Create a Plan
- Optimize the Plan
- Get Status
- Get completed Plan
Code: Select all
{"id":"00000000-0000-0000-0000-000000000000","description":"Test Route Trip","locations":[{"id":"Start","type":"DEPOT","latitude":50.73117,"longitude":7.10052,"includeLastMeters":true,"matchSideOfStreet":false,"applyVehicleDependentServiceTimeFactor":true,"openingIntervals":[{"start":"2024-03-06T08:00:00+01:00","end":"2024-03-06T20:00:00+01:00"}]},{"id":"Location 1","type":"CUSTOMER","latitude":51.5159395432446,"longitude":9.27642819335112,"includeLastMeters":true,"matchSideOfStreet":false,"applyVehicleDependentServiceTimeFactor":true,"openingIntervals":[{"start":"2024-03-06T08:00:00+01:00","end":"2024-03-06T20:00:00+01:00"}]},{"id":"Location 2","type":"CUSTOMER","latitude":51.670419413097285,"longitude":10.230704532272371,"includeLastMeters":true,"matchSideOfStreet":false,"applyVehicleDependentServiceTimeFactor":true,"openingIntervals":[{"start":"2024-03-06T08:00:00+01:00","end":"2024-03-06T20:00:00+01:00"}]},{"id":"Location 3","type":"CUSTOMER","latitude":52.729127711123866,"longitude":8.8410603595343034,"includeLastMeters":true,"matchSideOfStreet":false,"applyVehicleDependentServiceTimeFactor":true,"openingIntervals":[{"start":"2024-03-06T08:00:00+01:00","end":"2024-03-06T20:00:00+01:00"}]},{"id":"Location 4","type":"CUSTOMER","latitude":52.786041492721942,"longitude":8.2988423970259717,"includeLastMeters":true,"matchSideOfStreet":false,"applyVehicleDependentServiceTimeFactor":true,"openingIntervals":[{"start":"2024-03-06T08:00:00+01:00","end":"2024-03-06T20:00:00+01:00"}]},{"id":"Location 5","type":"CUSTOMER","latitude":52.897727122550926,"longitude":10.521510108222701,"includeLastMeters":true,"matchSideOfStreet":false,"applyVehicleDependentServiceTimeFactor":true,"openingIntervals":[{"start":"2024-03-06T08:00:00+01:00","end":"2024-03-06T20:00:00+01:00"}]},{"id":"Destination","type":"CUSTOMER","latitude":53.54897,"longitude":9.99337,"includeLastMeters":true,"matchSideOfStreet":false,"applyVehicleDependentServiceTimeFactor":true,"openingIntervals":[{"start":"2024-03-06T08:00:00+01:00","end":"2024-03-06T20:00:00+01:00"}]}],"vehicles":[{"id":"Vehicle 1","capacitiesChangePosition":"BETWEEN_TRIPS","profile":"EUR_TRAILER_TRUCK","startLocationId":"Start","endLocationId":"Start","serviceTimePerTransportStop":0,"serviceTimeFactor":1.0,"ignoreMixedLoadingProhibitions":false}],"transports":[{"id":"Transport to Location 1","pickupLocationId":"Start","pickupServiceTime":0,"deliveryLocationId":"Location 1","deliveryServiceTime":0},{"id":"Transport to Location 2","pickupLocationId":"Start","pickupServiceTime":0,"deliveryLocationId":"Location 2","deliveryServiceTime":0},{"id":"Transport to Location 3","pickupLocationId":"Start","pickupServiceTime":0,"deliveryLocationId":"Location 3","deliveryServiceTime":0},{"id":"Transport to Location 4","pickupLocationId":"Start","pickupServiceTime":0,"deliveryLocationId":"Location 4","deliveryServiceTime":0},{"id":"Transport to Location 5","pickupLocationId":"Start","pickupServiceTime":0,"deliveryLocationId":"Location 5","deliveryServiceTime":0},{"id":"Transport to Destination","pickupLocationId":"Start","pickupServiceTime":0,"deliveryLocationId":"Destination","deliveryServiceTime":0}],"planningHorizon":{"start":"2024-03-06T08:00:00+01:00","end":"2024-03-06T20:00:00+01:00"}}
Now I would like to start the optimization process with the following function:
Code: Select all
public void StartOptimizationAsync(string apiKey, Guid planId)
{
using (var client = new HttpClient { BaseAddress = new Uri("https://api.myptv.com/routeoptimization/v1/")})
{
// Add apiKey to Header
client.DefaultRequestHeaders.Add("apiKey", apiKey);
RouteOptimizationClient routeOptimizationClient = new RouteOptimizationClient(client);
routeOptimizationClient.StartOptimizationAsync(planId, OptimizationQuality.STANDARD, null, null, null);
}
}
planId would be "c243f8dd-fa43-417b-94ef-aba566d7d199" in this case.
In the request, the task will instantly be cancelled (at this line):
Code: Select all
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
Code: Select all
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at FormsMapCS.RouteOpt.RouteOptimizationClient.<StartOptimizationAsync>d__20.MoveNext()
I also tried to post the ID of the created plan at the API code sample website (https://developer.myptv.com/en/document ... imise-plan) and get the following error:
Code: Select all
{
"traceId": "9a61b152a96c475ca38752adffbc4cf7",
"errorId": "15f342b9-6276-49cf-8738-3ad48dfaab12",
"description": "A requested resource does not exist.",
"errorCode": "GENERAL_RESOURCE_NOT_FOUND",
"causes": [
{
"description": "The ID does not exist.",
"errorCode": "GENERAL_INVALID_ID",
"parameter": "id",
"details": {
"value": "c243f8dd-fa43-417b-94ef-aba566d7d199"
}
}
]
}
Thank you in advance,
Tobias Zylka