GET next page in JSON with rest message
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2023 01:01 AM
Hi, I have an external api that returns 1000 records at a time with the get call, this api has pagination, my goal is to take some properties of the JSON object that the api returns and put them in an array and then do the match between the fiscal code of the sys_user table and the nationalId property of the object in the array:
getIdsCoreHr();
function getIdsCoreHr(){
var token;
var intUtils = new sn_hr_core.successFactorsUtils();
token = intUtils.getToken();
var instanceName = gs.getProperty('instance_name');
var r;
if(instanceName.indexOf('prod') != -1){
r = new sn_ws.RESTMessageV2('success_factors_api_prod', 'GETPERNATIONALID N008');
}else if(instanceName.indexOf('test') != -1){
r = new sn_ws.RESTMessageV2('success_factors_api_test', 'GETPERNATIONALID N008');
}else {
r = new sn_ws.RESTMessageV2('success_factors_api_dev', 'GETPERNATIONALID N008');
}
r.setRequestHeader("Authorization", "Bearer " + token);
var response = r.execute();
var responseBody = JSON.parse(response.getBody());
var httpStatus = response.getStatusCode();
//var arr = responseBody.d.results;
//gs.info(JSON.stringify(arr));
var arr = responseBody.d.results.map(function(obj){
return { nationalId: obj.nationalId, personIdExternal: obj.personNav.employmentNav.results[0].personIdExternal, userId: obj.personNav.employmentNav.results[0].userId
};
});
//gs.info('Array di oggetti: '+JSON.stringify(arr));
while(responseBody.d.__next){
r.setEndpoint(responseBody.d.__next);
response = r.execute();
responseBody = JSON.parse(response.getBody());
arr = arr.concat(responseBody.d.results.map(function(obj){
return { nationalId: obj.nationalId, personIdExternal: obj.personNav.employmentNav.results[0].personIdExternal, userId: obj.personNav.employmentNav.results[0].userId};
}));
}
gs.info('Arrayi: '+JSON.stringify(arr));
}
the url in JSON is in property"__next" i tried to do this, but give me an error in this lin: arr = arr.concat(responseBody.d.results.map(function(obj){
0 REPLIES 0