How to send a POST request for the Custom Location Extension - here-api

I am trying out the HERE Maps REST API's - Custom Location Extension and run into a problem. It was mentioned that a POST request using the Corridor Search Using Coordinates for Custom Locationscan be used instead of a GET request if I want to submit a request with a large coordinate set, but the example POST request was not in the documentation.
I tried to figure out how to submit a POST request and this was how far I got:
Request:
POST /v1/search/corridor HTTP/1.1
Host: customlocation.cit.api.here.com
?app_id={YOUR_APP_ID}
&app_code={YOUR_APP_CODE}
&route=52.51978,13.388211,
52.5198326,13.3882084,
52.5198402,13.3883495,
52.5147705,13.3891602,
52.514758,13.389155
&radius=100
&layerId=30
Response:
{
"message": "Required parameters have not been provided",
"status": "400 Bad Request",
"error": "Required String parameter 'route' is not present",
"targetLayerId": null
}
Notes:
I wrote it here using the HTTP format
This request was the same GET request in the documentation and I just tried to convert it as a POST request by moving the query parameter into the body and sending the request using POST.
Body datatype is set as RAW TEXT
Edit:
(Further trial)
I also tried to move all the query params from the body to the url except route.
POST /v1/search/corridor ?app_id=Qk8YkRrHMbbbpkVipwIZ
&app_code=tYSXrAAHGEOcUB_cxbPQSA&radius=100&layerId=852 HTTP/1.1
route=52.51978,13.388211, 52.5198326,13.3882084,
52.5198402,13.3883495,
52.5147705,13.3891602,
52.514758,13.389155
Response:
{
"message": "Required parameters have not been provided",
"status": "400 Bad Request",
"error": "Required String parameter 'route' is not present",
"targetLayerId": null
}

I poked at this a bit and was able to get a response via POSTing by removing the route from the querystring and sending it as a form key/value pair. I used the demo credentials, and am testing using the Chrome plugin "Postman". My POST URL looks like this:
https://customlocation.cit.api.here.com/v1/search/corridor?layerId=30&radius=100&app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg
and then I set either a form-data or x-www-form-urlencoded key of "route" and then the value was a string of coordinates. And then it came back with a successful response. I did get the same error you mentioned when trying to put any payload as raw text.
Things I don't know: is there some limit on the form data values?
Good luck. I do agree that the official document is pretty light on the POST examples, especially since they explicitly suggest that as a method for sending large payloads.

Related

What to do with an array of Salted Base64 strings?

I have been given this challange, to "hack" a website to register in it, with some given hints. It includes 3 steps.
1.site_url/login - a POST request with login credentials (username, password - I have these) in the body of the request. After this it gives a JSON response that looks like this:
{
"token": "U2FsdGVkX18VaaqQc/R3Xi3jQtMMlPNku0YJzn0KNMYX0GY2ZELDfA5smRduUs5Cf519WmgaQnA+j6MpwCsvi/699R5oaUdXHCrgzrsZEKM="
}
Every time I send the request I get a different token from the previous one.
site_url/keys - a GET request with the token in the Authorization field of the header. It returns an array of 500 base64 strings that look like this:
[
"U2FsdGVkX19UgyaPxxLVM2J5LIzQPR+FDjjMWkSWcOseMSfGPWTrnC4EAIzB6EbmKS9jewVBq9BCf9FiHQDlxipYADA3A2i+jTYt0028sOrd/dkrAZCXVJBbNUDWYy6+",
"U2FsdGVkX1/9YThiCftxiLRK6GpEY6iouivp5eGCzCfv+HVoKeaS8z/Ut7BFWAm4yVTUasl87MM2pR47EIVJZ8A62sPmfTtGabz9PMlOKCnf1UKRAZFr69dZzQy71jc7",
......
"U2FsdGVkX1/yN0jrC5VPyzbiLZ5HAiPREyojo9sb+dUw+pYcGmIUocoh9m8SeQsItKFElyVz/7xhaGkrBmpvOsdFNLFsIcfObVqZ1H7T9ZAPXoZibg9+tVRDYV/3VQWm"
]
Every time I send this it gives me a different strings from the previous ones.
3.site_url/register - a POST request with the token in the Authorization field of the header (without it responds "unathorized") and one of the keys from the aray in the body JSON as such:
{
"key": "U2FsdGVkX18vwo3TVGLIwbxvkJ4NIf1GhBBIkNw9deRciB9O6/aC9KkFxVZ09WrxzB2YFncchsNY/hZYec/Hxvj1wlCK+7iZAyqNaW0hIBm17lZEloIwJVVfjX9wlkVr"
}
It returns:
{ error: 'Forbidden: Invalid registration key' }
I am assuming that I need to "bruteforce" those 500 keys and see which one works, but so far I couldn't do that as after few requests the website gives error 503 or 502. From my side it seems like the website is getting down (even when I check on my phone with mobile data). After couple of minutes it again starts working. I am using node.js and fetch API.
List of things I tried so far:
-changed referrer in the fetch options
-generated random IP adress for 'X-Forwarded-For' in the request header
-put these in the fetch options credentials: "omit", cache: "no-store"
-tried doing step 2 and changin the Authorization field in the header for every key in the array
List of things I want to try but don't know how:
-try decrypting those salted Base64 strings
-try somehow combining those strings in the array into a file
Hope the explanation was clear.
What can I try else or what am I doing wrong?

How to execute ElasticSearch agg query from Apache Nifi using InvokeHTTP?

I want to execute the following query from Apache Nifi:
GET /myindex/_search
{
"size": 0,
"aggs": {
"range": {
"date_range": {
"field": "Datetime",
"ranges": [
{
"from": "2017-02-17T16:00:00Z||-1H/H",
"to": "2017-02-17T16:00:00Z||/H"
}
]
}
}
}
}
I want to get the value of doc_count.
I tried to use InvokeHTTP and directly pasted the above-defined query into the field HTTP Method. I also set Remote URL to http://localhost:9200. I connected InvokeHTTP with PutFile in order to save a response on the disk. The relationship is Response.
When I run InvokeHTTP, it does not give me any error. However, it neither outputs any result (FlowFile for Response). I am sure that the result is not an empty set, because I tested this query with curl.
What is wrong with my approach? Should I define HTTP Method in some different way?
For verbs like POST, PUT, and PATCH, you'd normally have the above JSON body as the content of a flow file and pass that to InvokeHttp, setting the correct verb and URL there. However the InvokeHttp documentation states that the message body will not be sent for a GET verb.
The good news is that the Elasticsearch REST API for the search endpoint supports both GET and POST. From their latest doc: "Both HTTP GET and HTTP POST can be used to execute search with body. Since not all clients support GET with body, POST is allowed as well."
I would set the content of a flow file to the above JSON body (perhaps using GenerateFlowFile or ReplaceText), then use POST as the verb.
There is a JsonQueryElasticsearch processor, which supports JSON elasticsearch queries.
Your query goes into the Query field.
The processor has hits and aggregations relations for you to process the result.

HTTP request header field "optdata"

So, I googled a lot but couldn't find a HTTP request header field called "optdata". I am working on allowing the user to watch DRM protected videos on chromecast device. I am following a document from drmtoday.com which says:
For Widevine, the metadata must be carried inside the “optdata” field,
inside the HTTP request header with name “dt-custom-data” or
“x-dt-custom-data”.
I understand that the header key name is "dt-custom-data" but couldn't find any reference explaining what exactly is optdata.
If I just encode the following data to base64 and pass it as 'dt-custom-data' header, the request fails saying that 'HTTP Status 412 - Precondition failed'.
{
"userId":"12345",
"sessionId":"RWFzdGVyZWdn",
"merchant":"a-merchant"
}
It just means that dt-custom-data and x-dt-custom-data headers support key/value pairs. optdata is a recognised key.
E.g.
dt-custom-data: optdata={ "userId":"12345", "sessionId":"RWFzdGVyZWdn", "merchant":"a-merchant" }

Description text for 404 errors headers - changing 'Not Found'

This question was asked many times before, but I wanted to ask about different aspect of it.
My testcase:
header("HTTP/1.0 404 Not Found"); // and
header("HTTP/1.0 404");
result in server returing header:
HTTP/1.1 404 Not Found
But it's also possible to do:
header("HTTP/1.0 404 Oh... sorry, did not find");
Where is this possibility coming from? Is it proper (does not make any complications?) to change Not Found string?
It's not that I want to change it as none will ever see it except for somone checking headers. But I'm courious.
Rather not. This header is standarized and should be always returned as is - in the common form:
HTTP/1.1 404 Not Found
If you need to pass any additional info to the client, pass it in the responses body and in standarized way as well, e.g.:
{
"status": 404,
"code": 509, //some internal code
"message": "Can not find resource for ID: XXX"
}

Why "Invalid Content Type"

Trying to update a data field on a lead record in Marketo. Using C#. I send:
{"action":"updateOnly","input":[{"email":"dfranks#gmail.com","leadQuality":"Hot"}]}
And get back:
{"requestId":"d98e#14b2d7dd1f3","success":false,"errors":[{"code":"612","message":"Invalid Content Type"}]}
Why the Invalid Content type message? The field leadQuality is legit. The email address exists. I've tried a number of different fields and always the same message. Access token is good too.
Content-Type is a HTTP header. Usually, you set it to application/json for REST calls.
You should do this in the code where you generate the HTTP request or REST call.
I found text/json as Content-Type and Accept header value in one of the marketo examples. You might try one of the two choices.
Here are a couple of things to check:
As #StephenKing mentioned, I would check that your Content-Type HTTP
Header is set to "application/json".
I would also confirm that the custom field you created for "leadQuality"
has a String data type.

Resources