Here Fleet Telematics CalculateRoute service not accessible using api key - here-api

I'm trying to use the Here Fleet Telematics CalculateRoute.json service, to calculate trip costs (toll, etc). The sample page uses api_id and api_key for authentication. In my (Freemium) account, I don't see a way where I can generate that.
What I did is copy the request the sample site makes, and replace the app_id and app_key parameters with apikey=**key**. I also removed the jsoncallback parameter.
I get the back following JSON:
{
"faultCode": "s14e781b4-b577-4b58-86bb-359ee5c8a979",
"responseCode": "400",
"message": "The request is missing the app_id and app_code parameters. They must both be passed as query parameters. If you do not have app_id and app_code, please obtain them through your customer representative or at http://developer.here.com/myapps."
}
Update:
What I hope to achieve, is use the POST http method. According to https://developer.here.com/documentation/fleet-telematics/api-reference.html, section "Calculates a route with additional fleet telematics features", that should be possible.
The exact request message is (without actual api key):
POST https://fleet.ls.hereapi.com/2/calculateroute.json
Content-Type: application/json
{
"apiKey": "**SNIP**",
"waypoint0": "38.72639,-9.14949",
"waypoint1": "47.54881,7.58782",
"detail": "1",
"maneuverAttributes": "none",
"linkAttributes": "none,sh",
"legAttributes": "none,li",
"currency": "EUR",
"departure": "",
"tollVehicleType": "3",
"trailerType": "2",
"trailersCount": "1",
"vehicleNumberAxles": "3",
"trailerNumberAxles": "2",
"hybrid": "0",
"emissionType": "5",
"fuelType": "diesel",
"height": "4m",
"trailerHeight": "400",
"vehicleWeight": "12000",
"limitedWeight": "40t",
"disabledEquipped": "0",
"minimalPollution": "0",
"hov": "0",
"passengersCount": "1",
"tiresCount": "14",
"commercial": "1",
"heightAbove1stAxle": "1m",
"width": "2.55",
"length": "16.5",
"mode": "fastest;truck;traffic:disabled",
"rollups": "none,country;tollsys",
"alternatives": "1"
}
This returns the following:
HTTP/1.1 401 Unauthorized
Content-Type: application/json
Date: Mon, 01 Jun 2020 11:10:09 GMT
Server: nginx-clojure
Content-Length: 74
Connection: Close
{
"error": "Unauthorized",
"error_description": "Token or apiKey is missing."
}
Whereas, passing all the same values as url arguments in a GET request works.

You need to use the following endpoint:
https://fleet.ls.hereapi.com/2/calculateroute.json?apiKey={YOUR_API_KEY}&...
See Send a Request and Calculate Toll Cost documentation pages.

Related

Failed to fetch for application/octet-stream for small subset of users

I have two versions of an API I can toggle via a feature flag. (One that returns application/json and another that returns application/octet-stream)
When I enabled the feature flag to use the new application/octet-stream There seems to be a small subset of users for the API where they received failed to fetch. The users where the octet-stream API works and doesn't have the same browser versions and OS. The different users have same browser versions and operating system.
This is the request header I send for both API.
"headers": {
"accept": "*/*",
"accept-language": "en-US,en;q=0.9",
"authorization": "...",
"content-type": "application/json",
"sec-ch-ua": "\".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"", // They would be using Chrome and it might be v102
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "// I believe this would be Windows 10",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
},
"referrer": "...",
"referrerPolicy": "no-referrer-when-downgrade",
"body": "...",
"method": "POST",
"mode": "cors",
"credentials": "include"
This is the error from the logs (its similar to errors where there's no connection but the server receives the request and the other APIs seem to be returning correctly based on the logs)
"error": {
"message": "Failed to fetch",
"name": "TypeError",
"stack": "TypeError: Failed to fetch\n (...the chunks it failed at)"
},
Does anyone know what could be causing this issue? Am I missing an request or response header like maybe changing accept-encoding? or is it maybe a corporate firewall?
I had the same problem. The main cause of this - free space on disk where Chrome catalog located. See details https://stackoverflow.com/questions/10988569/storage-limits-on-chrome-browser,

HTTP 400 response received

The following HTTP request was sent and an HTTP 400 response was received. What is wrong with the request that caused it to fail?
POST /api/v2/organizations/4523jddfgd/projects HTTP/1.1
Host: www.reddit.com
Content-Type: application/json
Authorization: Bearer VALID_API_TOKEN
[
"name": "Project 1",
"package": "Standard",
"address": {
"street": "12456 Main St",
"city": "Dallas",
"zip": "75200",
"state": "TX",
"country": "USA"
}
]
This is an interview question, can you help guys ?
Have a look at the MDN wiki page about HTML status code 400.
Status code 400 points to a client side error e.g. malformed request body. Another reason could be that a required header is missing. As indicated in the MDN wiki page you should not attempt to send the very same request unmodified again as the result will be the same as it is not a server side issue.
What you should do instead is: consult the API documentation again and make sure that no header is missing and the request body is valid (i.e. valid JSON/ XML/ whatever in the correct structure).
Looking at your request I can see that the body is not valid JSON.
[
"name": "Project 1",
"package": "Standard",
"address": {
"street": "12456 Main St",
"city": "Dallas",
"zip": "75200",
"state": "TX",
"country": "USA"
}
]
This cannot be parsed, hence the error. An array cannot hold properties. What is missing is a { and } after the [ and before the closing ].
Using the following request body should work.
[
{
"name":"Project 1",
"package":"Standard",
"address":{
"street":"12456 Main St",
"city":"Dallas",
"zip":"75200",
"state":"TX",
"country":"USA"
}
}
]
EDIT
As #Evert pointed out, it is more likely that you need to replace [] with {} as POST requests are used to create single new resources. But the only way you can be absolutely sure is by reading the API documentation.
{
"name":"Project 1",
"package":"Standard",
"address":{
"street":"12456 Main St",
"city":"Dallas",
"zip":"75200",
"state":"TX",
"country":"USA"
}
}

Write validation failed for table row of type 'PurchPurchaseOrderLineEntity'

I'm trying to post the the purchase order line details from postman using odata and I'm getting the following error.
{
"error": {
"code": "",
"message": "An error has occurred.",
"innererror": {
"message": "Write validation failed for table row of type 'PurchPurchaseOrderLineEntity'. Infolog: .",
"type": "Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataValidateWriteException",
"stacktrace": " at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateProcessor.CreateEntity_Save(ChangeOperationContext context, ChangeInfo changeInfo)\r\n at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateManager.<>c__DisplayClass10_0.<CreateEntity>b__1(ChangeOperationContext context)\r\n at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.ChangeInfo.ExecuteActionsInCompanyContext(IEnumerable`1 actionList, ChangeOperationContext operationContext)\r\n at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.ChangeInfo.TrySave(ChangeOperationContext operationContext)\r\n at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateManager.SaveChanges()\r\n at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataDelegatingHandler.<SaveChangesAsync>d__3.MoveNext()"
}
}
}
I have tried checking these links but I'm not getting a breakthrough:
https://powerusers.microsoft.com/t5/Connecting-To-Data/Error-creating-order-line-in-Dynamics-365-for-Operations/td-p/11927
https://community.dynamics.com/365/financeandoperations/f/dynamics-365-for-finance-and-operations-forum/378486/error-while-submitting-po-from-external-system-odata-d365-f-o
Below is my payload
{
"dataAreaId": "XXXX",
"LineNumber": 1,
"PurchaseOrderNumber": "XXXX-PO-000009",
"ReceivingSiteId": "1",
"LineDescription": "XXXXXXX XXXX XXXX",
"ItemNumber": "SKU0000012530",
"DIOTOperationType": "Blank",
"LineAmount": 9687.19,
"PurchasePriceQuantity": 1,
"PurchasePrice": 9687.19,
"PurchaseUnitSymbol": "EA",
"OrderedPurchaseQuantity": 1,
"DeliveryAddressName": "XXXXX XXXXX XXXX",
"ProcurementProductCategoryName": "XXXXXX XXXXX XXXX",
"ReceivingWarehouseId": "TG",
"VendorInvoiceMatchingPolicy": "ThreeWayMatch",
"RequestedDeliveryDate": "2021-09-03T12:00:00Z"
}
Anyone who can help me on this?
NB: The Purchase order header is working without any problem.
Despite the missing information in the question, I tried to reproduce the issue. My test setup was a 10.0.20 environment with contoso demo data. I used the DEMF company and created a new purchase order since the existing ones were either already invoiced and/or intercompany.
I created the new purchase order for vendor DE-001 and was able to create lines in it using an OData request sent by Postman.
While testing, I noticed that the response Postman receives does contain the infolog messages which are missing in the question. Either they were removed (in which case please [edit] the question and add them) or the version of D365 does not include them (in which case please [edit] the question to add the version information).
I also noticed that the payload in the question contains fields ItemNumber and ProcurementProductCategoryName. As far as I know, a purchase line can have only one of those two, but not both. If you manually create a line with either one, the other one will be locked for editing. So please retry your request without either the ItemNumber or the ProcurementProductCategoryName field.
For the record, here are the payloads that worked in my test setup:
Payload with procurement category
{
"dataAreaId": "DEMF",
"LineNumber": 1,
"PurchaseOrderNumber": "000011",
"ReceivingSiteId": "1",
"LineDescription": "XXXXXXX XXXX XXXX",
"ProcurementProductCategoryName": "PAYROLL",
"DIOTOperationType": "Blank",
"LineAmount": 47.11,
"PurchasePriceQuantity": 1,
"PurchasePrice": 47.11,
"PurchaseUnitSymbol": "EA",
"OrderedPurchaseQuantity": 1,
"DeliveryAddressName": "XXXXX XXXXX XXXX",
"ReceivingWarehouseId": "11",
"VendorInvoiceMatchingPolicy": "ThreeWayMatch",
"RequestedDeliveryDate": "2021-09-03T12:00:00Z"
}
Payload with item number
{
"dataAreaId": "DEMF",
"LineNumber": 1,
"PurchaseOrderNumber": "000009",
"ReceivingSiteId": "1",
"LineDescription": "XXXXXXX XXXX XXXX",
"ItemNumber": "D0001",
"DIOTOperationType": "Blank",
"LineAmount": 47.11,
"PurchasePriceQuantity": 1,
"PurchasePrice": 47.11,
"PurchaseUnitSymbol": "EA",
"OrderedPurchaseQuantity": 1,
"DeliveryAddressName": "XXXXX XXXXX XXXX",
"ReceivingWarehouseId": "11",
"VendorInvoiceMatchingPolicy": "ThreeWayMatch",
"RequestedDeliveryDate": "2021-09-03T12:00:00Z"
}

App asking about itself with an app token

Is there an app token equivalent to the "/me" alias? In other words, is there a way that an application can ask for data about itself without having to hardcode its application ID in the "/{app-id}" request? Essentially, all I want is the app ID itself and I could extract that from the app token, but the token is supposed to be opaque and String manipulation to do that extraction seems hokey. Before I do the hokey thing, was wondering if there's a better way for an application to ask about itself.
/app is a shortcut for 'current app' and will work with a user access token, page access token or app access token
Example:
https://graph.facebook.com/v2.0/app?access_token=<APP ACCESS TOKEN>
Response:
{
"category": "Utilities",
"daily_active_users": "0",
"daily_active_users_rank": 1079202,
"icon_url": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yE/r/7Sq7wKJHi_5.png",
"link": "https://www.facebook.com/apps/application.php?id=[SNIPPED]",
"logo_url": "https://fbcdn-photos-c-a.akamaihd.net/hphotos-ak-xpa1/t39.2081-0/p75x75/[SNIPPED].png",
"mobile_web_url": "http://www[SNIPPED]",
"monthly_active_users": "1",
"monthly_active_users_rank": 1208403,
"name": "test app",
"subcategory": "Other",
"weekly_active_users": "1",
"id": "[SNIPPED]"
}

Send Table Data via Ajax and Web Api

I have tables with different column and row count as JSON on client side, e.g.:
[
["", "Kia", "Nissan", "Toyota", "Honda"],
["2008", "-5", "11", "12", "13"],
["2009", "20", "-11", "14", "13"],
["2010", "30", "15", "-12", "readOnly"]
]
I want to send this table to server via ajax and ASP.NET Web Api. What is the best way to do this?
I always get null as value when i want to post as text and receive it as [FromBody]string value. I can't use a class because of different table sizes?
the answer was in the ajax code. I didn't had the right data parameter. Right is:
$.ajax({
url: '../webapi/Products',
type: 'POST',
dataType: "text",
data: "="+JSON.stringify( data ),
success: function (test) {
alert(test);
},
error: function (test) {
alert("Error");
}
then i can use e.g. JArray from JSON.NET to parse the value string.

Resources