Receiving "Invalid_Request" response from Google-DistanceMatrix api in VBA - google-distancematrix-api

I'm sending an XML Request to the google-distancematrix api with a string that looks like:
https://maps.googleapis.com/maps/api/distancematrix/xml?origin=Grafton,+VA&destination=Yorktown,+VA&key=myKey
and am getting the following back:
<DistanceMatrixResponse>
<status>INVALID_REQUEST</status>
</DistanceMatrixResponse>
I'm obviously doing something wrong when formatting the request string, any recommendations?

turns out the syntax should be "origins" and "destinations" (plural) instead of "origin" and "destination"

Related

JAX-RS GET: MessageBodyReader not found for media type=text/plain

I'm getting following error while trying to do JAX-RS GET request:
MessageBodyReader not found for media type=text/plain, type=class com.intuit.accountant.services.common.cdm.Job, genericType=class com.intuit.accountant.services.common.cdm.Job
Below is my code:
Response response = target("jobs/Hello")
.request()
.header("intuit_offeringid", "testOfferingId")
.header(RequestHeaders.REALM, CommonUtil.DEFAULT_REALM_ID_FOR_INTUIT_EMPLOYEE)
.header(RequestHeaders.AUTH, "002923")
.header(RequestHeaders.TICKET,"00303")
.get(Response.class);
What does this error mean? How can I fix this?
You need to post all the code. The error is almost assuredly not happening in that code sample you posted. The get(Response.class) is converting it to a generic http response where you can see the response payload, status, response headers etc.
What you didn't post would most likely look somemthing like this. response.readEntity(com.intuit.accountant.services.common.cdm.Job)
In this case you don't have a reader registered to convert a text/plain response from the server to an entity. I don't know if the response was supposed to be json/xml and you are receiving text because there was an error of some kind. You should check the response as text like this to see what you are getting. This will probably point you in the right direction. If you are getting text you would have to write an implementation of MessageBodyReader to convert the plain text into an entity.
Try this...
System.out.println("Response body is " + response.getEntity(String.class));

variables post in koa framework

hi where is the data in post call in koa without co-body or bodyparse or why this error
Error: invalid JSON, only supports object and array
at parse (d:\Proyectos\koaJsTest\node_modules\co-body\lib\json.js:56:13)
co-body performs this regex unless the "strict" option is set to false:
/^[\x20\x09\x0a\x0d]*(\[|\{)/
Perhaps your json is making it to co-body as a URL-encoded string?
Its either going to be the format of the JSON that you are uploading if you are setting the Content-Type to application/json.
Otherwise, may be using the wrong Content-Type. For example if you were uploading files where the Content-Type should be multipart/form-data but you accidentally set the Content-Type to application/json when it should you would see this error.
This has tripped me up in the past.

Parsing JSON with a Javascript Date object in Ruby

I am using a SOAP API that returns XML but with JSON strings within the response envelope. For most of the API calls this has not been a problem but there is one that returns Javascript new Date objects that is causing problems when using JSON.parse. Here is a simplified example of the response I am getting.
"{\"History\":[ {\"Timestamp\":new Date(1380024020923)}]}"
When using JSON.parse I get the following error.
JSON::ParserError: 399: unexpected token at '{"Timestamp":new Date(1380024020923)}]}'
Is there a nice way to parse this string or am I going to have to use some regex/string trickery? Has anyone come across this way of returning a date object and I would like to understand the advantage?

Firefox HTTP resource test post parameter

I'm using HTTP Resource Test on Firefox and want to simulate a POST request. However I didn't find where to write the post parameters. There are only URI, Representation and Headers, is there any way that I can pass with some post parameter? (In Json format?)
The payload of the post should go in the body of the request. It's shown here:
https://addons.cdn.mozilla.net/img/uploads/previews/full/54/54035.png?modified=1297743921
For example, if you were posting a JSON document you could just paste the JSON in the "Body" text area.
The payload of the post should go in 'Client Request' / 'Representation'.
It's shown on this screenshot.
As an aside, this answer describes an excellent test server to use as a sanity-check.

HttpWebRequest/Response throwing error "Not Found"

I am making an API call to a REST service. The REST service returns an XML string that contains a user token if the password submitted is correct, or an XML string with data if it isn't.
Here is an example if the password is incorrect:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<authenticationResponse>
<statusCode>403</statusCode>
<errors>
<error>
....
</error>
</errors>
<timestamp>2011-03-31 22:45:03 GMT</timestamp>
</authenticationResponse>
With this code below, it appears .NET is translating this to an actual error. I still want it to read the XML data and ignore any error:
RequestData requestData = (RequestData)result.AsyncState;
HttpWebResponse response =
(HttpWebResponse)requestData.Request.EndGetResponse(result);
How I can ignore the error but still create the stream to read the XML?
Catch WebException, check the exception status, read the response. See these questions for examples:
Catching a specific WebException (550)
WebException when reading a WebException's response stream
Your code isn't translating this into an actual error - a HTTP status code of 403 is "Forbidden".
HTTP "Not Found" has a HTTP status code of 404 so it looks like the HTTP endpoint you're requesting doesn't exist in the REST service.
Ok so I figured it out, there's a few parts here.
First off the API is generating that xml when the parameters passed don't meet whats expected. In this case, if the password is incorrect, it'll pass back the 403.
The error is an error, so the framework treats it as such, however the error contains a response anyways, you just have to get the response off the error. This is essentially the answer to the question. Have to catch it the error and snag the response off the error to read the data in the stream, which is what Mauricio was getting to.
Essentially, I guess all the answers here are correct, or pieces of it, just took a little digging to put it all together.
Thanks Guys.

Resources