Creating Job from REST API returns a request property name error - rest

I have my Asset and MediaProcessor ready. Now I am trying to encode my asset. When I send the request specified in the tutorial (http://msdn.microsoft.com/en-us/library/jj129574.aspx):
{
"Name":"CurlTestJob",
"InputMediaAssets":[
{
"__metadata":{
"uri":"https://wamsbluclus001rest-hs.cloudapp.net/api/Assets('nb%3Acid%3AUUID%3A429967f5-4709-4377-bab2-4680ae2a0dd87')"
}
}
],
"Tasks":[
{
"Configuration":"H.264 HD 720p VBR",
"MediaProcessorId":"nb%3Ampid%3AUUID%3A2e7aa8f3-4961-4e0c-b4db-0e0439e524f5",
"TaskBody":"<?xml version=\"1.0\" encoding=\"utf-8\"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset>JobOutputAsset(0)</outputAsset></taskBody>"
}
]
}
I get the following response
{
"odata.error":
{
code: "";
message:
{
lang: "en-US";
value: "Parsing request content failed due to: Make sure to only use property names that are defined by the type";
};
};
}
I am using api-version 2.2
Can someone explain to me where am I wrong?

Try setting the Header "DataServiceVersion: 2.0"
I ran into the same issue when using "DataServiceVersion: 3.0"

The error says that properties in json file does not match the properties in the deserialized type.
http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.mediaservices.client.iasset.aspx shows that IAsset has property Uri, but say nothing about __metadata. You could try to change your json to
"InputMediaAssets":[{
"Uri":"https://wamsbluclus001rest-hs.cloudapp.net/api/Assets('nb%3Acid%3AUUID%3A429967f5-4709-4377-bab2-4680ae2a0dd87')"
}],

Related

Using Request Body in Azure Data Factory

I have a working GET request in Postman where the body contains the query as seen below
The body is as follows
{
"query": {
"bool": {
"must": [
{
"term": {
"Vrvirksomhed.cvrNummer": "12345678"
}
}
]
}
}
}
Now i'm trying to get the same GET to work in Aure Data Factory but somehow it seems that the syntax needs to be different as it' doesn't use it correctly. Does it need to be wrapped somehow ?
This is because the ADF will ignore the Request body when your Request method is GET. So it can't work.
You can click '{}' button to view the code of Copy activity.
Even if your request body has content, there isn't requestBody property in source.
If you change your request method to POST, it will show.
So you can change your request method to POST to have a try.

Elastic search - Unable to filter the JSON exact body using RestClient

Trying to query the exact JSON body by using Elastic search with RestClient API, but getting the whole body as response with hits,_source,etc.
So tried the filter_path [[filter_path=hits.hits._source]] approach in order to resolve this, but even that won't help to fetch exact body and coming with _source tag as mentioned below filter_path Response.
Can any one suggest please howt to get the exact json body as response like
{ "testAcct":"1234" }
Client.java:-
RestClient client = RestClient.builder(
new HttpHost(HOST, 9200, HTTP)).build();
Response response1 = client.performRequest("GET", SERVICE_URL + "_search",
Collections.<String, String>emptyMap(), new BasicHeader("testAcct", "1234"));
System.out.println(EntityUtils.toString(response1.getEntity()));
Response:-
{
"took":6,
"timed_out":false,
"_shards":{
"total":1,
"successful":1,
"failed":0
},
"hits":{
"total":21,
"max_score":1.0,
"hits":[
{
"_index":"testindex",
"_type":"testexternal",
"_id":"AVmHwA7Pkw5MudRUOp-q",
"_score":1.0,
"_source":{
"testAcct":"1234"
}
}
}
]
}
filter_path Response:-
{
"hits":{
"hits":[
{
"_source":{
"testAcct":"1234"
}
}
}
}

Need one help regarding fetching data value from response

Need one help regarding fetching data value from response.
Below is my response which I got after hitting URL.
{
"response": {
"Error Message": "Invalid Input missing",
"success": "false""
}
}
In this I want to read "Error Message" through POSTMAN test. For same reason I have written below code, but it is not working due to space between key.
var data = JSON.parse(responseBody);
tests ["Verify Error message"] = data.response.Error Message==="Invalid Input - Mandatory data(Company ID/source Id/SalesRep Ids/ContactPerson Ids) missing";
You're trying to use Error Message as a field with a space in it. Try:
tests ["Verify Error message"] = data.response.["Error Message"]==="Invalid Input - Mandatory data(Company ID/source Id/SalesRep Ids/ContactPerson Ids) missing";
This is not good to compare string.
In your response you must have like this,
{
"response": {
"Error Message": "Invalid Input missing",
"success": "false",
"responseCode" : 400
}
}
for more response codes, please go to this link,
http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
Then after do comparison,
var data = JSON.parse(responseBody);
if(data.reponse.responseCode == '400'){
// do stuff
}

Missing parameters with RESTful request when upgrading to Grails 2.3.0

I am using Grails with RESTful to develop my web application. Everything works fine, till I upgrade my application to Grails 2.3. Here is my UrlMappings:
I still send request, submit or do some other things normally, but in POST, PUT requests, the parameters are missing. Server just recognize only the parameters I put on the URL directly, but the remain I enclose in form or model when submit cannot be found in the "params" variable. He is my UrlMappings:
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?"{ constraints {} }
name apiSingle: "/api/$controller/$id"(parseRequest:true){
action = [GET: "show", PUT: "update", DELETE: "delete"]
constraints { id(matches:/\d+/) }
}
name apiCollection: "/api/$controller"(parseRequest:true){
action = [GET: "list", POST: "save"]
}
name api2: "/api/$controller/$action"(parseRequest:true)
name api3: "/api/$controller/$action/$id"(parseRequest:true)
"/"(view:"/welcome")
"500"(view:'/error')
}
}
I have read the latest document of Grails 2.3, at http://grails.org/doc/latest/guide/theWebLayer.html#restfulMappings
but I think it is not clear. I have tried it follow the documentation but have no result. And there are no any sample about using Grails 2.3 with RESTful for me to refer.
How can I make it work normally as before, and can access all parameter values in REST request? Thank you so much!
According to this http://grails.1312388.n4.nabble.com/Grails-2-3-and-parsing-json-td4649119.html parseRequest has no effect since Grails 2.3
If you use JSON as request body you can accees request params as request.JSON.paramName
As a workaround you can add a filter that will populate data from JSON to params:
class ParseRequestFilters {
def filters = {
remoteCalls(uri: "/remote/**") {
before = {
if (request.JSON) {
log.debug("Populating parsed json to params")
params << request.JSON
}
}
}
}
}
Adding on to Kipriz's answer and cdeszaq's comment, you can write a recursive method to inject nested params. Something along these lines:
public void processNestedKeys(Map requestMap, String key) {
if (getParameterValue(requestMap, key) instanceof JSONObject) {
String nestedPrefix = key + ".";
Map nestedMap = getParameterValue(requestMap, key)
for (Map.Entry<String, Object> entry : nestedMap.entrySet()) {
String newKey = nestedPrefix + entry.key;
requestMap.put(newKey, getParameterValue(nestedMap, entry.key))
processNestedKeys(requestMap, "${nestedPrefix + entry.key}");
}
}
}
public static Map populateParamsFromRequestJSON(def json) {
Map requestParameters = json as ConcurrentHashMap
for (Map.Entry<String, Object> entry : requestParameters.entrySet()) {
processNestedKeys(requestParameters, entry.key)
}
return requestParameters
}

asp.net Web Api - Default Error Messages

Is there a way of changing Web Api's default behavior for error messages, such as:
GET /trips/abc
Responds with (paraphrased):
HTTP 500 Bad Request
{
"Message": "The request is invalid.",
"MessageDetail": "The parameters dictionary contains a null entry for parameter 'tripId' of non-nullable type 'System.Guid' for method 'System.Net.Http.HttpResponseMessage GetTrip(System.Guid)' in 'Controllers.TripController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."
}
I'd like to avoid giving out this rather detailled information about my code, and instead replace it with something like:
HTTP 500 Bad Request
{
error: true,
error_message: "invalid parameter"
}
I'd be able to do this inside the UserController, but the code execution doesn't even go that far.
edit:
I've found a way of removing detailed error messages from the output, using this line of code in Global.asax.cs:
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy =
IncludeErrorDetailPolicy.LocalOnly;
This produces a message like this:
{
"Message": "The request is invalid."
}
which is better, however not exactly what I want - We've specified a number of numeric error codes, which are mapped to detailed error messages client-side. I would like to only output the appropriate error code (that I'm able to select prior to output, preferrably by seeing what kind of exception occured), for example:
{ error: true, error_code: 51 }
You might want to keep the shape of the data as the type HttpError even if you want to hide detailed information about the actual exception. To do that, you can add a custom DelegatingHandler to modify the HttpError that your service throws.
Here is a sample of how the DelegatingHandler might look like:
public class CustomModifyingErrorMessageDelegatingHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return base.SendAsync(request, cancellationToken).ContinueWith<HttpResponseMessage>((responseToCompleteTask) =>
{
HttpResponseMessage response = responseToCompleteTask.Result;
HttpError error = null;
if (response.TryGetContentValue<HttpError>(out error))
{
error.Message = "Your Customized Error Message";
// etc...
}
return response;
});
}
}
Maggie's answer worked for me as well. Thanks for posting!
Just wanted to some bits to her code for additional clarification:
HttpResponseMessage response = responseToCompleteTask.Result;
HttpError error = null;
if ((!response.IsSuccessStatusCode) && (response.TryGetContentValue(out error)))
{
// Build new custom from underlying HttpError object.
var errorResp = new MyErrorResponse();
// Replace outgoing response's content with our custom response
// while keeping the requested MediaType [formatter].
var content = (ObjectContent)response.Content;
response.Content = new ObjectContent(typeof (MyErrorResponse), errorResp, content.Formatter);
}
return response;
Where:
public class MyErrorResponse
{
public MyErrorResponse()
{
Error = true;
Code = 0;
}
public bool Error { get; set; }
public int Code { get; set; }
}