infobip chatbot fetching data - infobip

TypeError: invokeMember (get) on com.infobip.bot.engine.anticorruption.external.coding.execution.CodingAttributeApi#5c7c1bc1 failed due to: Arity error - expected: 1 actual: 2
found a error while fetching data from api.
i hit a api got back the response code 200.
data was not getting set in a infobip variable .
let list = attributeApi.get('getavailablity');
attributeApi.set('departure_time',list[8-1].dT );
attributeApi.get('return_time', list[8-1].aT);
attributeApi.set('total_amount', list[8-1].totalAmount);

Just change:
attributeApi.get('return_time', list[8-1].aT);
to:
attributeApi.set('return_time', list[8-1].aT);

Related

why (in promise) SyntaxError: Unexpected token < in JSON at position 0?

I need public data, so I'm going to bring it.
total api url : https://www.chungbuk.go.kr/openapi-json/pubdata/pubMapForest.do
fetch('/openapi-json/pubdata/pubMapForest.do?pageNo=1&numOfRows=2').then(
(data) => data.json()).then(json=>console.log(json))
);
// package.json
"proxy":{
"target":"https://www.chungbuk.go.kr"
}
but I get strange data.
when i use postman, I got normal data.
What should I do?

Getting 'expected { Object (message, detail) } to have property 'count' error in API testing using cypress

I want to assert the total count received from the response.
This is my code:
cy.request({
method:'GET',
url:'https://ibis-qa.droicelabs.us/api/practice/orders/?q=&limit=100',
failOnStatusCode: false,
headers:{
accept: "application/json"
}
}).then(Response => {
let body = JSON.parse(JSON.stringify(Response.body))
cy.log(body)
expect(body).has.property('count','27')
})
and this is the error that I have got
Please use
expect(body).has.property('count', 27)
as the value is a number
(see screen-shot, there are no quotes around 27)
You are not getting the JSON response you think you should have.
If go to the URL in the browser, I get this
{"message":"field required","detail":[{"loc":["header","authorization"],"msg":"field required","type":"value_error.missing"}]}
which is what is partially shown in the screenshot of the error message.
This is an error response from the server, and it means your request is not correct.
Then you can directly use the assertion like this. You don't need to parse or stringify.
expect(Response.body).to.have.property('count',27)
You can check this example from the cypress docs.

Sending data to Firebase from Matlab

I want to save data to firebase from Matlab. Does firebase have similar api calls like ThingSpeak? How can i send JSON data from matlab by making API calls?
I am making API calls from Matlab like for JSON:
Firebase_Url = 'https://ecgproject-86945.firebaseio.com/';
writeApiKey = '***';
data = ['api_key=',writeApiKey,'&name=',"JSOpn9ZC54A4P4RoqVa"];
response = webwrite(Firebase_Url,data)
%data = struct('api_key',writeApiKey,'field1',data); //also tries this
%options = weboptions('MediaType','application/json');
The Error:
Error using readContentFromWebService (line 46)
The server returned the status 405 with message "Method Not Allowed" in response to the
request to URL https://ecgproject-86945.firebaseio.com/.
Error in webwrite (line 139)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
Error in Untitled (line 16)
response = webwrite(Firebase_Url,data)
From reading the mathworks documentation on webwrite you need to use the two-parameter version of the method, passing in the additional information inside the second, data object:
data = ['api_key=',writeApiKey,'&name=',"JSOpn9ZC54A4P4RoqVa"];
response = webwrite(FirebaseURL,data)
Okay I found the solution apparently i didn't add .json at the end of the URL. Thank You. Here is the solution:
Firebase_Url = 'https://***.firebaseio.com/Channel1.json';
response = webwrite(Firebase_Url,'{ "first": "Jack", "last": "Sparrow" }')

Matlab webread with google translation api

I have the same problem when i called Google translation API, this is my code
url = 'https://translation.googleapis.com/language/translate/v2'
Options.ContentType ='Josn';
options.KeyValue='XXXXXX';
response = webread(url,options)
`options.KeyName = 'apikey';
the following error appeared :
Error using readContentFromWebService (line 37) The server returned the message: "Forbidden" for URL, 'https://translation.googleapis.com/language/translate/v2' (with HTTP response code 403).
Error in webread (line 115) [varargout{1:nargout}] = readContentFromWebService(connection, options);
I filled key value as it is in my console, any one help?

Angular 2 how to read Custom error message from backend

My problem with Angular 2 that was not exist in AngularJS, that I was sending the error message as a string with backend API call in case I have error, with error status 401 as example, the problem now that I can't read this message from Angular2 http response message, while I can do that from AngularJS:
I tried the following codes and nothing was helpful:
Promise:
this._http.post('/login',{email: 'email#example.com', password: '123'})
.toPromise()
.then((resp) => console.log(resp), (error) => console.log(error));
Observable:
this._http.post('/login',{email: 'email#example.com', password: '123'})
.subscribe(response =>console.log(response), (error) => console.log(error));
And from back-end I send response as a text, for OK or Unauthorized, for OK i send back String token == UUID.randomUUID().toString();, for error I send back message like String error = " Invalid credentials ";, the problem is that the console.log works and print the text for success (token in this case), but in case error, its just prints: Response with status: 200 for URL: null.
If I change code to JSON.stringify(error) I get something like this:
{"_body":{},"status":401,"ok":false,"statusText":"Unauthorized","headers":{"null":["HTTP/1.1 401 Unauthorized"],"Access-Control-Allow-Headers":["Origin"," X-Requested-With"," Content-Type"," Accept"," Referer"," User-Agent"],"Access-Control-Allow-Met
hods":["POST"," GET"," PUT"," DELETE"," OPTIONS"],"Access-Control-Allow-Origin":["*"],"Allow":["*"],"Content-Length":["36"],"Content-Type":["text/plain; charset=utf-8"],"Date":["Tue"," 23 Aug 2016 14:53:25 GMT"]},"type":2,"url":null}
As you can see the error test not even mentioned inside the Object !!
I tried to change the response for error from backend to return json like this:
{
"message": "invalid email or password"
}
I can get the result inside _body, and I can only read it like this: console.log(error._body.message) ! but i feel its something wrong this way, and I don't want to response as a json in this case.
For angularjs (angular 1), its so simple just to print the response and everything is cool, while in angular 2 its a really problem.
What the problem, and how I can solve this issue without any refactor to backend?
Edit:
I'm using Angular 2.0.0-rc.4 and same for http : `"#angular/http": "2.0.0-rc.4"
Mothanfar
In my case I'm working with the Asp Web Api as back end,this thing is making me crazy as well, the only solution I found is transform in a json and read the message, I know is really ugly but works for me.
Regards.
CheckError(error: any) {
let servermsg: any = JSON.parse(error._body)["ModelState"]["Login"][0];
if (servermsg) {
this.showMsg = true;
this.msg = servermsg;
}
}
If you are returning JSON object from the server, you may use the below code at client side:
let errMsg: ErrorMessage = err.json();
console.log(errMsg.message)
export class ErrorMessage {
message:string;
}