I would like to obtain in a response of http-connector, only the “number” element, but I cannot obtain it.
I’m trying to have an inline Javascript with the following statement:
S(response).prop(“status”).prop(“number”).numberValue();
but it shows an error: SPIN/JACKSON-JSON-01004 Unable to find ‘status’
What it’s wrong in the statement?
Rest response to parse:
{
“status”: {
“number”: 200,
“type”: “OK”,
“description”: “Status OK”
}
}
There is no obvious issue with your expression. I would debug further to see if response indeed contanis the Json string you posted. The error shows that response exists, but the content differs.
This working example I just created may help you:
https://github.com/rob2universe/camunda-http-connector-example
If this does not help, you could share more info, e.g. the process model, server log, service you are calling...
Related
I would like to return a response code of 400 to the client after throwing an error in my Lambda function. (via REST API - GET)
Here is the response from the Lambda function:
{
"errorMessage": "{\"status\": 400, \"result\": \"Invalid Input\", \"errorDescription\": \"Incorrect data format, should be YYYY-MM-DD. Refer to our documentation for further instructions.\", \"documentation\": \"link\"}",
"errorType": "ValueError",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 69, in lambda_handler\n raise ValueError(date_error_json)\n"
]
}
In the settings of the Integration Response of the API I set up the Lambda Error Regex as .*"status":400.*
For the mapping template I have:
#set ($errorMessageObj = $util.parseJson($input.path('$.errorMessage')))
{
"status" : "$errorMessageObj.status"
}
When calling the API I mostly receive this result:
{"errorMessage": "{\"status\": 400, \"result\": \"Invalid Input\", \"errorDescription\": \"Incorrect data format, should be YYYY-MM-DD. Refer to our documentation for further instructions.\", \"documentation\": \"link\"}", "errorType": "ValueError", "stackTrace": [" File \"/var/task/lambda_function.py\", line 69, in lambda_handler\n raise ValueError(date_error_json)\n"]}
And the status of the HTTP request tracked in Chromes Developer Tools shows as 200.
My assumption is that the Regex is incorrect since it should at least return a 400 HTTP response, even if my mapping template was incorrect.
However, surprisingly a few times I was able to get the desired result of a 400 HTTP response, as well as the desired format displayed as:
{
"status" : "400"
}
The way I got to this result was the following: When I changed the Regex around to .*400.* (which did not help) and then back to .*"status":400.*. However, as soon as I send another request to the API it was back to the situation before. (No other changes were made, only a second API request)
And this is actually repeatable, every time I switch back and forth between those Regex values I get my desired result. For 1 API request and then it switches back.
I know it sounds weird. Here is a quick screenshare of it: https://www.loom.com/share/365a7c48119944658e157c5e0a5178e8
I would like to know if there is an issue with my code or if this might be a bug on Amazon's end.
For anyone coming across the same problem in the future. I have found out the following 2 things:
After trying again to set .*400.* a little later it worked fine. Of course, this may not be a good idea, because if you return any results, that contain 400 anywhere in their response, they could incorrectly trigger a 400 HTTP response.
The workaround I found was to use .*Invalid Input.*. Since it is not expected that regular results returned from the API would contain this phrase, this should work reliably.
I created a WebAPI with Visual Studio 2017 using its .Net Core template. I am able to test my Get() code with Postman and everything works correctly. Now, I would like to send a Post request so it calls the following code.
[HttpPost]
public void Post([FromBody] string value)
{
Console.WriteLine("value" + value);
}
However, I get the following error when call
https://localhost:44364/api/carbon?value=100
{
"": [
"A non-empty request body is required."
]
}
I am sure the problem lies with they way my Postman is setup but it looks correct.
Any suggestions? Thank you!
Updated per suggestion
I added key/value to the body and received "The input was not valid."
You do not need to use Query string.You need to post the string with raw json, and do not forget the double quotation marks.Refer to here to get more details on post methods by Postman.
The error message you're receiving is very descriptive of the problem - you haven't provided a body in your request.
Click "Body" in Postman (next to "Headers") then select the type of body you want to send, for example x-www-form-urlencoded and then add a key/value pair beneath, e.g. test and hello world.
Hit "Send".
I am trying to use THIS RESTful API: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
To do this, I am using THIS C++ SDK: https://github.com/Microsoft/cpprestsdk
The Binance API returns everything as JSON, which is where I think my issue lies.
My code is here: https://pastebin.com/SeBAxvA0
I think the error is here in this function (commented as well in pastebin):
void print_test(json::value const & value){
if(!value.is_null()){
//I am doing something wrong here I'm pretty sure.
auto response = value[L"responseData"];
//"responseData" is probably not what should be here I think?
auto results = response[L"serverTime"];
wcout << results.as_integer() << endl;
}
}
Basically, I am trying to just test out this API by doing a simple GET method for the server time from the Binance API. According to the Binance documentation:
Check server time
GET /api/v1/time
Test connectivity to the Rest API and get the current server time.
Weight: 1
Parameters: NONE
Response:
{
"serverTime": 1499827319559
}
So I would like to do a GET request for that JSON, and then have my C++ program output the value of serverTime. When I try to run my code as is, I get an error saying:
error: no viable overloaded operator[] for type
'const json::value'
auto response = value[L"responseData"];
However, I am following along with an example from the C++restSDK found here:
http://mariusbancila.ro/blog/2013/08/02/cpp-rest-sdk-in-visual-studio-2013/
I think my issue has something to do with the two lines under the comment I made on line 45 in my pastebin. Presumably, I am assigning the wrong values to one or both of the variables under that line. I know this is a pretty specific help request, but does anyone know what I'm doing wrong and how to get the value of serverTime to display?
I solved this issue on my own after much digging :)
Error was in this function and it is now fixed with this code:
void print_test(json::value const & value){
if(!value.is_null()){
json::value test = value;
cout << test["serverTime"] << endl;
}
}
I can't figure out if my problem has to do with my query or my response or something else.
In my route I'm using a queryRecord:
model(params) {
return this.store.queryRecord('invitation', {
'invitation_token' : params.invitationToken
});
},
I'm properly receiving on the server side but I'm testing the case where the invitation token no longer exists. Therefore, the server is returning a 400 with a json payload which has an explanation of the error.
{"error":"Error finding invitation"}
But back on the ember side I'm just getting two errors (really it is just one).
Error while processing route: accept-invitation Ember Data Request GET /api/users/invitation returned a 400
Error: Ember Data Request GET /api/users/invitation returned a 400
It used to be (under Ember 2.2.1):
Error while processing route: accept-invitation Adapter operation failed Error: Adapter operation failed
Error: Adapter operation failed
What am I supposed to be returning from the server in the case that the token wasn't found? These messages makes it looks like something unexpected happen within Ember.
I'd assume that a 400 would tell Ember that there was an error, and it would go to the error state for the route. But instead it goes to the error state at the application level and spits out these error messages in the log.
I'm expecting the server to return a 400, so I'm not sure why Ember is complaining. What should I be returning and how should I properly handle this?
I believe that your application should be returning a response that is formatted differently. As per the JSON API specification,
Error objects MUST be returned as an array keyed by errors in the top
level of a JSON API document.
The specification also specifies that the following members, among others, may be provided (see the link for the full list).
title: a short, human-readable summary of the problem that SHOULD NOT
change from occurrence to occurrence of the problem, except for
purposes of localization.
detail: a human-readable explanation
specific to this occurrence of the problem. Like title, this field's
value can be localized
status: the HTTP status code applicable to this problem, expressed as
a string value.
If you try returning something along the lines of what is below, how does the tooling behave?
{
"errors": [
{
"status": "400",
"title": "Error finding invitation"
}
]
}
I have did a sample example of dynamic loading templates using the Handlebars.SafeString(). Everything works fine expect Refresh the browser URL. When ever refresh the browser url i get an error i.e "Uncaught TypeError: Property 'undefined' of object # is not a function".And this error get only this line i.e return new Handlebars.SafeString(Template[Session.get('currentTemplate')]({dataKey: 'somevalue'}));. With out this line Works fine everything even Refresh also.I am using this Handlebars.SafeString() is to load templates dynamically. I didn't have any idea about this So please help me how to?.
And What is the use of dataKey in above Handlebars.SafeString()?
It looks like the Session dict is not populated when the call is made, and therefore Session.get('currentTemplate') is undefined. A simple safeguard should fix the problem, assuming you're in a reactive context:
if(! Session.get('currentTemplate')) return '';
return new Handlebars.SafeString(Template[Session.get('currentTemplate')]({dataKey: 'somevalue'}));