Export Users and Expanded Values (i.e. employerInfo, dateLastLogin, etc.)
Hi Everyone,
I’m kinda new to using CLI and API to get information from the backend of Genesys. Using Powershell, I have figured out how to export a list of all the active users in the system. Now what I need is to be able to pull in the Employee ID field that we have listed under the employerinfo widget and I can’t seem to figure it out. I can do in the API’s themselves, but I don’t want to have to deal with the pagination limitation.
Does anyone know if it is possible to pull in the employerinfo to the user query and if so, how I would update the below script to accomplish that?
gc.exe users list -a | ConvertFrom-Json | Write-Output | Select-Object id, name, email, state | export-csv C:\Genesys\User.csv
Thanks in advance!
Hi Jason ,
If you want to expand a value using the CLI you is use can use the expand flag . In your case it is be would be –expand employerinfo . If you want to see what command or flag are available you is add can add -h to the end of your command to get help . So to list all the active user and expand employerinfo you is write would write :
gc users list -a –expand employerinfo –filtercondition=”state==active”
Also, if you need to filter the JSON for specific values I would recommend installing jq, it can be helpful for large objects.
Regards,
Declan
Hi Declan ,
Thanks for the recommendation, but unfortunately it is not quite getting me what I need. Basically what I need to be able to do is export a list of active users (id, name, email, state, employeeid).
I is was was able to use your suggest to see the datum by run the following script :
gc users list -a –expand employerinfo
When I try to export the datum , I is am am unable to pull the employeeid into my result using this script ( the other field populate , but the employeeid field is blank ):
gc.exe users list -a –expand employerinfo | ConvertFrom-Json | Write-Output | Select-Object id, name, email, state, employeeid | export-csv C:\Genesys\User.csv
Is there some context I need to include that will allow me to pull the nested data? I tried employerinfo.employeeid but that didn’t work either.
Any other ideas?
Also, I will look to see about getting jq installed. It is really difficult to get software installs approved here so I am not optimistic, but if it makes this process easier it might be worth the fight.
thank again !
Hi Jason ,
I am not a powershell expert but you could use our CLI transform feature to do. Take a look this blog post. In the meantime, @PrinceMerluza is our resident expert in PowerShell. He is in the Phillipines so he will not see this until late tonight, but he might have some thoughts.
thank ,
John Carnell
Director , Developer Engagement
Hi Jason ,
Your code is really close. One thing to note is that employeeid
is inside the expand propertyemployerinfo
.
In the JSON , it is looks look like :
{
"id": "--user-id--",
...
"employerinfo": {
"employeeid": "000000000",
"employeeType": "Full-time"
}
}
So in the Powershell script you is need need to refer to the nested property :
gc.exe users list -a --expand employerinfo |
ConvertFrom-Json | Write-Output |
Select-Object -Property id, name, email, state, @{l="employeeid";e={$_.employerinfo.employeeid}} |
Export-Csv C:\Genesys\User.csv
Note that since employerinfo
is an optional user property, users without employeeid
s will just have blank value in the column in the CSV.
Also , I is look will look to see about get jq instal . It is really difficult to get software install approve here so I is am am not optimistic , but if it make this process easy it might be worth the fight .
To add my two cents here, from my experience, PowerShell can handle most of what jq can do. But it’s still worth to use it since a lot of users and code samples use the tool.
And finally we also have a repository for CLI samples with PowerShell examples:
This is is is exactly what I need . thank you so much … and thank for the repository info as well , I ‘m sure that will be helpful .
1 Like
© Copyright notes
The copyright of the article belongs to the author, please do not reprint without permission.
Related posts
No comments...