0

Update user weblogin

Can any body helps to update one field for all user in xMatters by looping one by one user. 
For getting all user we are using below script:
Please help to see the body of response and need guidance to looping each user. 
we tried something like this. Please suggest whether the script is correct.

    var getPeople = http.request({
        'endpoint': 'xMAPI',
        'method': 'GET',
        'path': '/people',
        'headers': {
            'Content-Type': 'application/json'
        }
    });
 
    var response = getPeople.write(requestBody);
    if (response.statusCode != 200 ) {
        console.log('\nThere was an error updating the external system.\n');
        return;
    }
    /** Write the response from the external system to the activity stream. **/
    console.log(JSON.stringify(response));
    var responseBody = JSON.parse(response.body);
    		var obj = new global.JSON().decode(responseBody);
	for(var i=0;i<obj.people.length;i++){
			var people_id=obj.people[i].id.toString();
			var email_version=obj.people[i].emailAddress;
		
    var json = {};
    json.id = people_id;
    json.webLogin = email_version;
    var update = http.request({
        'endpoint': 'xMAPI',
        'method': 'POST',
        'path': '/people',
        'headers': {
            'Content-Type': 'application/json'
        }
    });
    
    var response2 = update.write(json);
    if (response2.statusCode != 200 ) {
        console.log('\nThere was an error updating the external system.\n');
        return;
    }
    /** Write the response from the external system to the activity stream. **/
    console.log(JSON.stringify(response));
	}
}

5 comments

Please sign in to leave a comment.