Your organization acquires a new company. All the employees to be converted to new company and user accounts to be created. bulk user creation can be done through HDL. However, bulk password reset requires, user guid’s.
In this article, we are providing an automated solution to bulk reset passwords using R programming language.
library(httr)
library(jsonlite)
library(readxl)
library(dplyr)
library(zoo)
username = 'admin'
password = 'admin'
setwd(dir = "C:\Users\Aruna\automations\R")
filepath1 = "users_v1.xlsx"
# rjson object contains the request JSON
rxl = read_excel(path = paste0(getwd(), "/" ,filepath1))
%>% as.data.frame()
rxl = distinct(rxl)
s = ''
for ( i in 1:nrow(rxl)){
print(i)
if(i==1) {
s = paste0('{
"Operations":[
{
"method":"PATCH",
"path":"/Users/', rxl[i, c("USER_GUID")] ,
'","bulkId":"clientBulkId1",
"data":{
"schemas":[
"urn:scim:schemas:core:2.0:User"
],
"password":"', rxl[i, c("PWD")], '"
}
}')
} else {
s = paste0(s, ',{
"method":"PATCH",
"path":"/Users/', rxl[i, c("USER_GUID")],
'","bulkId":"clientBulkId1",
"data":{
"schemas":[
"urn:scim:schemas:core:2.0:User"
],
"password":"', rxl[i, c("PWD")], '"
}
}')
if(i==nrow(rxl)) {
s = paste0(s, ']
}')
}
print(s)
}
}
fun = function(x) {
if(index(x)==1) {
paste0('{
"Operations":[
{
"method":"PATCH",
"path":"/Users/', x$USER_GUID , '"
"bulkId":"clientBulkId1",
"data":{
"schemas":[
"urn:scim:schemas:core:2.0:User"
],
"password":"', rxl$PWD, '"
}
}')
}
paste0(',{
"method":"PATCH",
"path":"/Users/', rxl$USER_GUID , '"
"bulkId":"clientBulkId1",
"data":{
"schemas":[
"urn:scim:schemas:core:2.0:User"
],
"password":"', rxl$PWD, '"
}
}')
if(index(rxl)==nrow(rxl)) {
paste0(']
}')
}
}
link2 = 'https://hcas.fa.us1.oraclecloud.com:443/hcmRestApi/scim/Bulk' #/Users/086F5F2A146DB95FE050179035634956'
httr::POST (url =link2,
authenticate(username,password , type = "basic"),
body = s,
httr::add_headers(accept = 'application/json'),
httr::content_type('application/json'),
verbose()) = responseJson
# parse response JSON, and log
char_info=rawToChar(responseJson$content)
data_json = fromJSON(char_info)
data_json$Operations %>% as_tibble() = responseLog
write.csv(responseLog, file = "BulkPwdReset_log.dat")