How to send data to REST dataset in Azure Data Factory Dataflow? - rest

I am trying to use a REST Service as a Sink Dataset in my Dataflow, but it always fails with a Bad Request 400 Error.
Error
{"StatusCode":"DFExecutorUserError","Message":"Job failed due to reason: DF-REST_001 - Rest - Error response received from the server (url:https://my_url,request body: Some({"Name":"GREST"}), request method: POST, status code: 400), response body: Some({"error":{"name":"badRequest","message":"Request body has invalid format."}}))","Details":"com.microsoft.dataflow.Issues: DF-REST_001 - Rest - Error response received from the server (url:https://my_url,request body: Some({"Name":"GREST"}), request method: POST, status code: 400), response body: Some({"error":{"name":"badRequest","message":"Request body has invalid format."}}))\n\tat com.microsoft.dataflow.Utils$.failure(Utils.scala:75)\n\tat org.apache.spark.sql.execution.datasources.rest.RestClient.ensureSuccessResponse(RestClient.scala:430)\n\tat org.apache.spark.sql.execution.datasources.rest.RestClient.org$apache$spark$sql$execution$datasources$rest$RestClient$$executeRequest(RestClient.scala:415)\n\tat org.apache.spark.sql.execution.datasources.rest.RestClient.org$apache$spark$sql$execution$datasources$rest$RestClient$$executeSingleRowRequest(RestClient.scala:153)\n\tat org.apache.spark.sql.execution.datasources.rest.RestClient$$anonfun$savePartitionSingle$1$$anonfun$apply$mcV$sp$3.apply(RestClient.scala:106)\n\tat org.apache.spark.sql.execution.datasource"}

The status code 400 is a Bad Request error, and the server cannot process the request due to an error.
The possible reasons might be due to incorrect URL, malformed syntax, request body might have invalid JSON. Please check the URL and validate JSON data.

When you use copy activity and the method is POST, make sure that you send it in Additional headers section key -> "Content-Type" value -> "application-json"

Related

SOAP Fault response from Wiremock not detected as SOAPFault by API-Connect 2018

When I call the actual SOAP service (using Postman and SoapUI) with an invalid parameter value, it causes a SOAP-Fault response, with HTTP 200 .
I copied the body of the response into a Wiremock response file, whose corresponding mapping file returns HTTP 200.
When I use Postman to invoke the SOAP service and the mocked one, the 'Body' of the responses are identical (apart from headers, as the mocked response doesn't explicitly set any).
When my API invokes the actual SOAP service, the SOAPError is caught, the processing stops and the API is processed as defined in the 'catch' section.
However, when the API invokes the mocked SOAP service, the SOAPError is not detected after 'invoke', processing continues and produces an incorrect response.
This suggests that there is something 'extra' returned in a fault from a real SOAP service, that APIC uses to detect a SOAPError. What is it?
I would add it to the mocked response, if only I knew what it should be.
BTW: The response headers are the same for both valid parameters and the SOAP Fault for an invalid one.
[edit]
Thanks #Jan Papenbrock. Adding "Content-Type = text/xml" sorted it out.
I don't know why I thought I was receiving the same headers from real and mocked responses - total rubbish!
John
[/edit]
Had the same error with WireMock and fixed it with the help of answers to this question. In my case, the Content-Type header was missing.
I suggest you try the following:
Send Content-Type: text/xml as response header (or try application/soap+xml)
Return HTTP status code 500 for the SOAP fault response, according to the specification (note: status 400 did not work for me).
My stub generation looks like this:
static ResponseDefinitionBuilder errorInvalidStopResponse() {
responseWithBodyFile('response-error-invalid-stop.xml')
.withStatus(500)
}
static ResponseDefinitionBuilder responseWithBodyFile(String responseBodyFileName) {
aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBodyFile(responseBodyFileName)
}

Why Kafka REST Proxy API not Consuming data in JSON Format?

I'm try to access message hub instance by using kafka rest API. when i'm sending post request through Postman Client and giving Content-Type as application/vnd.kafka.json.v1+json it's giving me the following response
{
"error_code": 415,
"message": "HTTP 415 Unsupported Media Type"
}
could anyone please help me with that?.
I'm also passing api key in X-Auth-Token Header.
the accepted content-types when producing messages are
"application/vnd.kafka.binary.v1+json"
"application/vnd.kafka.v1+json"
"application/vnd.kafka+json"
"application/json"
but in all cases, the Message Hub REST service expects the content to be formatted as
"application/vnd.kafka.binary.v1+json"
i.e. the value of "value" to be base64-encoded.
E.g. something like
{"records":[{"value":"YmxhaGJsYWg="}]}

What response code should we use on a REST reply when the response data is an error message

We have a REST service where the response to a request may be an error message. A simple example is the request is a formula to calculate and the formula might have a divide by zero. In that case the response is an error code and error message.
So the communication with the REST service is all good. The service itself is responding to the request. But the response is an error message instead of the expected result.
In this case what is the best response code to use? 200 to say the entire communication process is good and we look in the returned JSON to determine if it’s an error? 500 to say it’s an error, but then look to see if we have the expected JSON to determine it was an error in the calculation? Some other code which says we are getting a response from the server but the response is an error message?
A simple example is the request is a formula to calculate and the formula might have a divide by zero. [...] In this case what is the best response code to use?
I would use 422 Unprocessable Entity
The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.
Don't rely only on HTTP code anyway, always add a description of the error in the body. I believe it's common practice to have all your endpoints reply with a JSON with success (true or false) and something like error (with the error message) if success if false, or data (with the result) if success is true.
For error messages we can use 4XX Bad Request
Look at this post, for various status codes.
http://www.restapitutorial.com/httpstatuscodes.html

Which HTTP code should be return from REST API?

im currently working on a website which has Spring at backend and Angularjs at front side and we had discussed about back end responses to handle frontend's message dialogs and i have a question to ask:
Lets say i have an API :
GET : /getstatistics
Request params : fromTime,toTime ( in timestamp format)
And if client make a request with invalid params like a string, which response code should be returned from server ? HTTP 400 bad request and response body with a message " fromTime and toTime should be in timestamp format" or HTTP 200 with same message?
I saw some Google's APIs for example Oauth, they're returning code 200 for a request with invalid access_token but ,in our project my opinion it should be HTTP 400 because Javascript has success and error callbacks, is it better for it just pop a red color dialog with message inside rather than a HTTP 200 code then still need to check the content of the message?
Any advides and opinions are appreciated.
Thanks!
You should be returning a 400 error for bad request. Check out this reference.
The server cannot or will not process the request due to something
that is perceived to be a client error (e.g., malformed request
syntax, invalid request message framing, or deceptive request
routing).
Please have a look at RFC7231#section-6
A client MUST understand the class of any status code, as indicated by
the first digit
and,
4xx (Client Error): The request contains bad syntax or cannot be
fulfilled
Bad syntax can be something like you've mentioned in your question (making a request with invalid parameters, like a string).
I keep these two references handy whenever I'm designing RESTful APIs, might be helpful for you too:
https://httpstatuses.com/
http://www.restapitutorial.com/httpstatuscodes.html
Yes you are right, the http code should be 400 in your case. Your discussion here normally should be whether you need to return 400 or 422. For this you can check the accepted response for this SO question 400 vs 422 response to POST of data
I think it has something to do with how the parameters are used. If you use the resource, then a 404 should return. If the data is simply not valid then we decide to set a 409 Status to the request. It can't full fill it at 100% because of missing/invalid parameter.
HTTP Status Code "409 Conflict" was for us a good try because it's
definition require to include enough information for the user to
recognize the source of the conflict.
Reference: w3.org/Protocols/
Edit:
In any case, the status code 200 is incorrect here because there is an error. In response, you can then return specific information like this:
{
"errors": [
{
"userMessage": "Sorry, the parameter xxx is not valid",
"internalMessage": "Invalid Time",
"code": 34,
"more info": "http://localhost/"
}
]
}

HTTP Status code for malformed POST body

What status code should a REST service return in response to a POST request containing a malformed / unparseable message body?
400 Bad Request
Straight from the specification:
The request could not be understood by the server due to malformed
syntax. The client SHOULD NOT repeat the request without
modifications.
Alternatively, if you need a more specific status you can create your own 4XX status for whatever API you might be designing.
400 - Bad Request
From Hypertext Transfer Protocol -- HTTP/1.1 (RFC-2616):
400 Bad Request
The request could not be understood by the server due to malformed
syntax. The client SHOULD NOT repeat the request without
modifications.
I'd say 412 Precondition Failed