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 can use the expand flag. In your case it would be --expand employerInfo. If you want to see what commands or flags are available you can add -h to the end of your command to get help. So to list all the active users and expand employerInfo you 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 was able to use your suggest to see the data by running the following script:
gc users list -a --expand employerInfo
When I try to export the data, I am unable to pull the employeeId into my results using this script (the other fields 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.
Thanks 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.
Thanks,
John Carnell
Director, Developer Engagement
Hi Jason,
Your code is really close. One thing to note is that employeeId
is inside the expanded property employerInfo
.
In the JSON, it looks like:
{
"id": "--user-id--",
...
"employerInfo": {
"employeeId": "000000000",
"employeeType": "Full-time"
}
}
So in the Powershell script you 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 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.
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 exactly what I needed. Thank you so much...and thanks for the repository info as well, I'm sure that will be helpful.
1 Like