Thanks to @dernc and @ethompson whose posts helped in creating the PowerShell script.
Below is the modified PowerShell Script which you can use to create Access Request in Bulk.
#sandbox
$ClientID = "XXXXXXXXXXXXXXXXXXXXXXXXX"
$SecretID = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"
$pair = "$($ClientID):$($SecretID)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($pair))
$BasicAuth1 = "Basic $encodedCreds"
#Get credentials and encrypt them
$tokenParam = @{
URI = 'https://my-tenant.api.identitynow.com/oauth/token'
Body="grant_type=client_credentials"
Headers = @{'Authorization' = "$BasicAuth1";"Content-Type"='application/x-www-form-urlencoded;application/json;charset=UTF-8'}
Method = 'POST'
}
$tokenResponse = Invoke-RestMethod @tokenParam
$token = $tokenResponse.access_token
$users = @()
$entitlementId = ""
foreach ($user in $users) {
$body = @{
requestedFor = @(
$user
)
requestType = "GRANT_ACCESS"
requestedItems = @(
[PSCustomObject]@{
type = "ENTITLEMENT"
id = $entitlementId
comment = "Assining entitlement to the users as per request from Karan"
}
)
}
(ConvertTo-Json $body -depth 5)
$params = @{
method = "POST"
uri = "https://my-tenant.api.identitynow.com/v3/access-requests"
body = (ConvertTo-Json $body -Depth 5)
headers = @{'Authorization' = "Bearer $token"}
ContentType = "application/json"
}
try {
$response = Invoke-RestMethod @params
$response
}
catch {
Write-Host $response
Write-Host $_.Exception.Message -ForegroundColor Red
Write-Host $_.Exception.ItemName -ForegroundColor Red
}
}