results.total is undefined in dojo/store/JsonRest? - dojo

I am following one of dojo/store/JsonRest tutorial (https://dojotoolkit.org/reference-guide/1.10/dojo/store/JsonRest.html#dojo-store-jsonrest). As mentioned in the tutorial I am returning "Content-Range: items 0-24/66" in the header from server side (java).
I have tested in SOAP UI as well and the header is there in the server response:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Range: items 0-3/6
Content-Type: application/json
Content-Length: 402
Date: Thu, 16 Mar 2017 01:14:23 GMT
When I access the total as in following
var results = store.query({
start: 0,
count: 3
}).then(function (deals){
//do something
});
results.total.then(function(total){
//do something
});
Here I am getting results.total is undefined error. Any idea?
Please see screen shot is the content of results.
Content of Results

The returned total is available as a further promise on the returned promise of data which returns the total number of available rows indicated in the Content-Range: header as a number, so you can retrieve it like this:
var results = store.query({
start: 0,
count: 3
}).then(function(deals) {
// move this promise inside outer promise
results.total.then(function(total) {
//do something
});
});

Did a few more research and found out that following code can be used to get both response data and total. Not really sure why it wasn't working on above code blocks though.
var results = store.query({
start: 0,
count: 3
});
results.then(function (data) {
// You can access the response data here
results.total.then(function (total) {
// You can access total here
});
});

Related

How to run the dependent request multiple times till the desired response is not achieved from request in test in Postman

I have Request A and Request B which I have to test in the Postman Test
Condition for testing these API is that Success of Request A is depended on the response of the Request B
When the request A is hit the response from the Request B send the initial value as 2 for attribute 2 then after 30 second the response of value change to 2.1 which is success of test
Request A
Request B
Response B
{
Attribute 1: Value 1
Attribute 2: Value 2  Value 2.1
Attribute 3: Value 3
}
Code written in Postman Test is below
pm.test("Check Success Status",function(){
let i =1;
do{
pm.sendRequest("Request B",function(err,res){
var JsonData=res.json();
if(JsonData.attribute2=="Value 2.1"){
{
break;
}else{
setTimeout(2000);
}
})
i++;
}while(i<5)
})
Please let me know if I have implemented the correct logic or is there any other way to do that ?
I would trigger the dependent request inside the body of the previous request like this:
pm.sendRequest(postRequest, (error, response) => {
console.log(error ? error : response.json());
console.log("First")
pm.sendRequest(postRequest, (error, response) => {
console.log(error ? error : response.json());
console.log("Second")
});
});

Curl doesn't download all the records from the website

Using the API to download the companies' complete call log. The documentation states that to download all without pagination to list 0 for number of records per page. This does not work for me. What am I doing wrong?
Tried 0
curl --request GET \
--url 'https://platform.ringcentral.com/restapi/v1.0/account/~/call-log?view=Simple&dateFrom=2019-07-26&dateTo=2019-07-28&page=1&perPage=0' \
--header 'accept: application/json' \
--header 'authorization: Bearer <MyToken>'
Expected full call log. Returned only 99 records
As per this link, "1000 is the max perPage setting. If there are more than 1000 records, you will be able to call the nextPage in a URL that's provided in the API response paging property."
https://forums.developers.ringcentral.com/questions/329/exporting-call-log-data.html
You can try removing the page option
As per this below link the solution to read at once without pagination they suggested is:
read all extensions under your account.
read call log of each
extension one at a time.
ref: https://forums.developers.ringcentral.com/questions/1254/how-to-read-all-users-call-logs-at-once.html
The documentation states that to download all without pagination to list 0 for number of records per page.
I searched through the docs, but couldn't find that line or anything specifically related.
The API Spec for the perPage query parameter for the current endpoint reads the following:
/restapi/v1.0/account/{accountId}/call-log:
get:
tags:
...
parameters:
...
- name: perPage
in: query
description: Indicates the page size (number of items)
default: 100
required: false
type: integer
...
Though by taking a look at one of the examples provided, I assume that to get max logs perPage should be set to 1000 and page should not be provided as the following function suggest:
function readCallLogs(){
var configs = {}
if ($('#phoneNumber').val() != "")
configs['phoneNumber'] = $('#phoneNumber').val()
if ($('#extension').val() != "")
configs['extensionNumber'] = $('#extension').val()
if ($('#direction').val() != "default")
configs['direction'] = $('#direction').val()
if ($('#type').val() != "default")
configs['type'] = $('#type').val()
if ($('#transport').val() != "default")
configs['transport'] = $('#transport').val()
configs['view'] = $('#view').val()
configs['showBlocked'] = $('#showBlocked').is(":checked")
configs['withRecording'] = $('#withRecording').is(":checked")
configs['dateFrom'] = $("#fromdatepicker").val() + "T00:00:00.000Z"
configs['dateTo'] = $("#todatepicker").val() + "T23:59:59.999Z"
configs['perPage'] = 1000
var url = "readlogs?access=" + $('#access_level').val();
var posting = $.post( url, configs );
posting.done(function( response ) {
var res = JSON.parse(response)
if (res.hasOwnProperty('calllog_error')){
alert(res.calllog_error)
}else{
callLogsData = new CallLogsData(JSON.parse(response))
drawGraphs()
}
});
posting.fail(function(response){
alert(response.statusText);
});
}
Hence you should try editing your initial call to match the following:
GET /restapi/v1.0/account/~/call-log?view=Simple&dateFrom=2019-07-26&dateTo=2019-07-28&perPage=1000 HTTP/1.1
Host: platform.devtest.ringcentral.com
Accept: application/json
Authorization: Bearer U0pDMDFQMTdQQVMwMHxBQUFBeHFCSjZGR3FSYkNJREcyQUlUNTUyN085b05PZEUza2R4VV9oWjF0ZzhKOUpEekJ4WDU5T2U1czFvSzJ3WGN4NF9QWWRPMEVYNENYQjd4dmJsWHJocGJRcC1BcDlrUHZIczcycTVONm13NDZJSWN6VnZ1YzNsU3NVY2doMnd2UHlCMGxkaC1MTXlfZFk5VS0yZUUtWnpRejhKUXJtT21yMFQ0ZHpKQ1AwbnhfQmRRTTRKazR3OVNuTVE4THNOa3BfcW1oX21mUGtQdWNkUVN4ZnRaUzd8Mkt2

Items: Get item revision difference returns empty array

I am trying to return the diffence in field values between two revisions using app authentication but I'm getting an empty array.
And when trying to use the api function "Get Item revision" I'm getting "Object not found" response.
Any help would be much appreciated :)
const podio = new Podio({
authType: 'app',
clientId: clientId,
clientSecret: clientSecret });
podio.authenticateWithApp(app_id, appToken, (err) => {
if (err) throw new Error(err);
podio.isAuthenticated().then(function () {
// ready to make API calls
apiRoutes.get('/item', function (req, res) {
podio.request('GET', `/item/702620400/revision/1899410196/1910867632`).then(function (responseData) {
res.json(responseData);
});
});
}).catch(err => res.send(err));
});
Podio documentation is not clear enough when describes calls for item revisions. Here is how it works, example in Ruby:
item_revisions = Podio::ItemRevision.find_all_by_item_id(item_id)
last = item_revisions.length - 1
revision_last = Podio::ItemRevision.find(item_id, last)
revision_beforelast = Podio::ItemRevision.find(item_id, last - 1)
diff = Podio::ItemDiff.find_by_item_and_revisions(item_id, last - 1, last)
Misleading part is revision_id vs revision vs item_revision_id.
For "Get Item revision" and "Get item revision difference" calls please use revision which goes for each item from 0 and increases by 1 with each new revision. Last revision available for item is item_revisions.length - 1 from example above.

HTTPS page returning HTML source and header rather than content?

I'm building a web app with PHP and Python (The site has SSL) and once in a very long while, randomly, the page returns the header message followed by the HTML source, rather than showing the page's content.
This happens sometimes once out of every 30 times I load the page, or other times once out of 500 or so times.
It's very random, too.
Other times it renders just fine.
Here's what the header looks like:
HTTP/1.1 200 OKServer: Apache/2.2
Content-Type: text/html; charset=UTF-8
Date: Wed, 22 Feb 2012 10:40:33 GMT
Transfer-Encoding: chunked
Connection: Keep-Alive
66c2
The 66c2 changes randomly
Either Apache is not recognizing the .php extension and isn't running the code through the PHP module (in which case you would see your PHP code in the browser) or else the content-type has something wrong with it and thus the browser will punt and just display it as text instead of rendering it. The only other thing I can think of off the top of my head is that PHP is sometimes not closing the response properly.
Here is a simple code to parse chunk-ed content:
//
// Unchunk http content. Returns unchunked content on success,
// false on any errors... Borrows from code posted above by
// jbr at ya-right dot com.
//
function unchunkHttpResponse($str=null) {
if (!is_string($str) or strlen($str) < 1) { return false; }
$eol = "\r\n";
$add = strlen($eol);
$tmp = $str;
$str = '';
do {
$tmp = ltrim($tmp);
$pos = strpos($tmp, $eol);
if ($pos === false) { return false; }
$len = hexdec(substr($tmp,0,$pos));
if (!is_numeric($len) or $len < 0) { return false; }
$str .= substr($tmp, ($pos + $add), $len);
$tmp = substr($tmp, ($len + $pos + $add));
$check = trim($tmp);
} while(!empty($check));
unset($tmp);
return $str;
}

Simple XmlHttpRequest AJAX not outputting desired status code

My first and very simple AJAX request not outputting "status 200 OK".. and instead outputs "0" .. What's wrong?
function doit(){
var httpxml = new XMLHttpRequest();
httpxml.onreadystatechange = function(){
if(httpxml.readyState == 4) {
alert(httpxml.status);
}
}
httpxml.open("GET", "http://localhost/test/ROUGH/TEST.php", true);
httpxml.send(null);
}
doit();
The main reason for status 0 is that it has run from the disk and not through a webserver.